I’ve been work­ing on some projects lately that use server side lan­guages like PHP.  I’m pretty com­fort­able cod­ing, but some­thing that has gen­er­ally eluded me is as to how I’ve been able to visit sites with URLs like:

http://www.sitename.com/whatever/you/want

Well, I finally came across how to achieve this effect.  Enter stage right, HTACCESS.

Apache servers (with mod_rewrite enabled) have the abil­ity to take the request from the user, rewrite it, and then dis­play the rewrit­ten requested page.

1
2
3
4
RewriteEngine On
Rewrite­Cond %{REQUEST_FILENAME} !-f
Rewrite­Cond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]

This will access the file:

http://www.domain.com/about.php

by typ­ing in the URL of

http://www.domain.com/about

Respect: Thanks to Dave Dash for this insight into cleaner URLS.  Go Green!

To get sim­i­lar results with an IIS server, visit Microno­vae.

Note: that I have a basic under­stand­ing of how servers work.  For more infor­ma­tion about Apache, visit their site.