M
M
mr_rakhimov2021-10-12 16:30:56
htaccess
mr_rakhimov, 2021-10-12 16:30:56

How to remove GET parameter from url using .htaccess file?

Hello, I have a problem with url. I have a link:
employeedb3/id?id=id_000001
, I need to convert it to the form:
employeedb3/id_000001

How can this be achieved using the .htaccess file without losing the GET parameters

Here is the code from the .htaccess file
Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} /pages/([^.]+)\.php [NC]
RewriteRule ^ /%1 [L,NC,R=301]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{ DOCUMENT_ROOT}/pages/$1\.php -f [NC]
RewriteRule ^([^.]+?)/?$ pages/$1.php [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1 \.php -f [NC]
RewriteRule ^([^.]+?)/?$ $1.php [NC,L]

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2021-10-12
@mr_rakhimov

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} /pages/([^.]+)\.php [NC]
RewriteRule ^ /%1 [L,R=301]

RewriteCond %{QUERY_STRING} (?:^|&)id=([^&]+)
RewriteRule ^id$ /%1? [R=301,L]

RewriteRule ^(id_\d+)$ pages/id.php?id=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/pages/$1\.php -f
RewriteRule ^([^.]+?)/?$ pages/$1.php [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f
RewriteRule ^([^.]+?)/?$ $1.php [L]

V
Viktor Taran, 2021-10-12
@shambler81

this is if you need any of the get parameters

RewriteCond %{QUERY_STRING} (?:^|&)id\=(.*)(?:$|&)
RewriteRule ^employeedb3/id$ https://employeedb3/%1? [L,R=301]

well, a special case
RewriteCond %{QUERY_STRING} (?:^|&)id\=(id_000001)(?:$|&)
RewriteRule ^employeedb3/id$ https://employeedb3/%1? [L,R=301]

%1 is not a typo, it is the first group of RewriteCond

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question