Archive

Archive for November, 2008

URL prettification in 10 seconds flat

November 29th, 2008 No comments

A word to all PHP, ASP, Python and Perl web-devs out there:

http://somewhere.com/contact.php

Is soooo 1990’s.

URL prettification has always been seen to be the exclusive domain of larger frameworks but with Apache it really isn’t that hard.

Simply paste the following into a file named ‘.htaccess’ (note the starting ‘dot’) and dump it in your website to allow the extension of your script to be ‘guessed’ by Apache should it not be provided.

This hack obviously requires mod_rewrite but since every hosting provider and their dog provides this these days i would say not having it enabled would be the exception rather than the rule

?Download .htaccess
1
2
3
4
5
RewriteEngine On
RewriteBase /
 
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$		$1.php [L]

ASP, Python and Perl people either add your .asp, .py or .pl sections under or above the .php bits or simply replace them.

There, now we can use:

http://somewhere.com/contact

But the old way (with .php extension) is still valid too.

Finally we put an end to this silly file extension nastiness.

Categories: HowTo's, PHP Tags: , ,