Nice urls with .htaccess

This code turns ugly urls full of parameters into user- and search-engine-friendly browser urls. And it’s totally automatic. This is a win-win-situation :)

Edit your .htaccess file like this if you want your urls to function like this:
http://domain.com/about -> http://domain.com/about.php

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]
# http://domain.com/about -> http://domain.com/about.php

Or, if you want
http://domain.com/about -> http://domain.com/index.php?q=about

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
# http://domain.com/about -> http://domain.com/index.php?q=about

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>