Answer the question
In order to leave comments, you need to log in
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
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]
this is if you need any of the get parameters
RewriteCond %{QUERY_STRING} (?:^|&)id\=(.*)(?:$|&)
RewriteRule ^employeedb3/id$ https://employeedb3/%1? [L,R=301]
RewriteCond %{QUERY_STRING} (?:^|&)id\=(id_000001)(?:$|&)
RewriteRule ^employeedb3/id$ https://employeedb3/%1? [L,R=301]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question