Have a Snippet?

Keep, track and share your code snippets with your friends



htaccess: Rewrite URLs #2 Share on Vkontakte

Rewrite URLs with .htaccess. If you use it then URL like "http://mydomain.com/user.php?show=JohnDoe" will be equivalent to "http://mydomain.com/JohnDoe/".

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+user\.php\?show=([^\s]+) [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ /user.php?show=$1 [L,QSA,NC]


Tag: htaccess, Rewrite, RewriteEngine, URL, Replace

0 Comments