How to have SEO friendly Urls using .htaccess



Occasionally, with your php site you do not have SEO friendly URLs. As an example, you have links that look like:

http://www.example.co.uk/brochure.php?cat_path=24

And you would like your URLs to look like this: http://www.example.co.uk/Concrete_Fence_Posts

Assuming your parameters are always named cat_path and product_id (if it exists) you can do something like this in .htaccess:

<?php
RewriteRule 
^([^/]+)/([d+])$         $1.php?cat_path=$2
RewriteRule 
^([^/]+)/([d+])/([d+])$ $1.php?cat_path=$2&product_id=$3
?>

Your URLs would then be in the format:

<?php
pagename
/cat_path
pagename
/cat_path/product_id
?>

For example:

<?php
http
://www.bentinckfencing.co.uk/brochure/24
http://www.bentinckfencing.co.uk/product/35/54
?>