Using Apache mod_rewrite to redirect old URLs
There are lots of examples and tutorials covering Apache and mod_rewrite, but generally they address the problem where you want to map a ‘nice’ url to your script. For example:
http://example.com/products/kitchen/cutlery
to
http://example.com/products.php?category=kitchen&sub-category=cutlery
is easily achieved with the following .htaccess rules:
RewriteRule ^([A-Za-z0-9\-]+)/([A-Za-z0-9\-]+)/([A-Za-z0-9\-]+)/? /one.php?action=$1&category=$2&subcategory=$3 [L]
However if you want to rewrite in the other direction it might not be immediately obvious that you cannot use rewrite rules with your GET URL variables. So if you want to go from
http://example.com/products.php?category=kitchen&sub-category=cutlery
to
http://example.com/products/kitchen/cutlery
you need to sniff the query variables as well as the script name.
Continue reading ‘Using Apache mod_rewrite to redirect old URLs’ »