Monday, September 19, 2005

Hiding Ugly URLs

This isn't necessarily a Real Estate related tip, but I've seen a lot of sites that have pages with URLs that expose a lot of parameters, which makes the address hard to read and type, and also tends to make the URL less preferable to search engines, so I thought I'd pass on a tip that a friend gave me recently. I'll give the example for PHP/apache, but you can also do this in other environments, though the specifics might be different.

Lets say that you have an URL such as

www.yoursite.com/entrygenerator.php?id=42

In PHP you can edit the .htaccess file,

and put in the following:

RewriteEngine on
RewriteRule ^([0-9][0-9]).html RewriteRule ^entrygenerator.php&id=$1

Now, you should be able to present the URL as simply www.yoursite.com/42.html

To also support 1 and 3 digit parms you'll need to add the following 2 entries:

RewriteRule ^([0-9]).html RewriteRule ^entrygenerator.php&id=$1
RewriteRule ^([0-9][0-9][0-9]).html RewriteRule ^entrygenerator.php&id=$1


This technique can also help to improve the security of your site by obscuring certain details such as the real name of the executable file.
Give it a try, and if you have trouble, research mod_rewrite (for PHP/apache at least)

1 comment:

Anonymous said...

This is great info. Thanks for the tip. Where are you from/work for?