Archive for the ‘.htaccess’ category

How to use mod_rewrite to create clean URLs

September 13th, 2009

Learn how to remove cruft from your URLs and give yourself greater flexibility while making things much easier for visitors and search engines.

Cruft and permalinks

How many times have you seen URLs like this?

Horrible, aren’t they? They look ugly, contain meaningless information and are hard to decipher. Wouldn’t it be nice if you could have URLs like this?

That is surely much more meaningful. The hierarchy of the directory structure makes it easy to infer what you’re likely to see on the page: a weblog entry from 23rd November 2000 called ‘Example’.

Another problem is link rot. What happens when your URLs are several years old? Will they still work? What if you ditch PHP and rewrite your site in Python, for example? All those URLs ending in .php will suddenly break, and visitors who’ve found your site in a search engine won’t get what they bargained for.

Yet another problem is that search engines often avoid URLs which contain the ? character, because they are likely to be just one node in a large database which could leave the spider going round in circles for a long time. If your URLs take that form then this may be why you haven’t found yourself in Google. » Read more: How to use mod_rewrite to create clean URLs