.htaccess URL Rewriting for SEO
One thing that people completely forget when planing their SEO campaign is just how important their url structure is to their on-site Search Engine Optimisation.
Google’s webmaster guidelines say the following: (External Link)
A site’s URL structure should be as simple as possible. Consider organizing your content so that URLs are constructed logically and in a manner that is most intelligible to humans (when possible, readable words rather than long ID numbers). For example, if you’re searching for information about aviation, a URL like http://en.wikipedia.org/wiki/Aviation will help you decide whether to click that link. A URL like http://www.example.com/index.php?id_sezione=360&sid=3a5ebc944f41daa6f849f730f1, is much less appealing to users.
Therefore, Google themselves are telling website designers to build websites with urls that are descriptive and logical, therefore entycing the click, you could call this a subtle call to action.
Many people have a PHP or script based website that requires input perameters to produce the page they requested.
With this in mind I am going to show you how to “rewrite” your urls to be search engine friendly.
A simple .htaccess file would look like this:
Options +FollowSymLinks
RewriteEngine onRewriteRule ^cat/([^/]*)\.html$ /search.php?cat_id=$1 [L]
So does that just look like a bit of a mess? - Let me explain:
Options +FollowSymLinks
RewriteEngine on
These two lines of code tell Apache to switch ON the rewrite engine. Thus telling Apache to interpret the incomming links and resrite them with this rule:
RewriteRule ^cat/([^/]*)\.html$ /search.php?cat_id=$1 [L]
But what does this rule do? This rule will make Apache interpret this url:
http://www.example.com/cat/19.html
as if we had actually typed in this url:
http://www.example.com/search.php?cat_id=19
What is the benefit of this? Well, for example, if we were to do this:
RewriteRule ^([0-9])/([^/]*)\.html$ /search.php?cat_id=$1 [L]
This would do the same to the following URL:
http://www.example.com/123/category-name.html
And the 123 would represent the category id.
.htaccess is very versitile. I have listed a load of .htaccess tools below:
.htaccess URL rewrite generator - Very Handy!
Some great .htaccess tips & tricks
A comprehensive guide to .htaccess
Top 5 .htaccess URL Rewrite Tools
If you have any great .htaccess resources or utilities, please feel free to post them below…