Home > Net >  .htaccess rewrite query string as path url
.htaccess rewrite query string as path url

Time:10-26

I searched for this question but only came across very specific answers that I couldn't tailor to my requirements.

My URL now looks like this: https://example.eu/?action=changepassword and I want it to look like this: https://example.eu/changepassword so text ?action= gets deleted.

I tried to adapt this but it didn't work.

CodePudding user response:

With your shown samples, please try following htaccess rules file. Please also make sure to clear your browser cache before testing your URLs.

RewriteEngine ON
##External redirect rules here....
RewriteCond %{THE_REQUEST} \s/?\?action=(\S )\s [NC]
RewriteRule ^ %1? [R=301,L]

##Internal rewrite rules to handle query string in backend.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /?action=$1  [L]
  • Related