Let’s say I have this URL:

http://example.com/users.php?name=tania

And I want this URL:

http://example.com/users/tania

I can do so with the following .htaccess:

.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?users/(.*?)/?$ /users.php?name=$1 [L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /users\.php\?name=([^\&\ ]+)
RewriteRule ^/?users\.php$ /users/%1? [L,R=301]

I can even still GET the URL query.

#apache #snippet

Rewrite Query String to Path with htaccess
1.45 GEEK