Wednesday, November 29, 2006

Mod Rewrite - changing url variables

The following Mod rewrite rule redirects

RewriteEngine On
RewriteBase /test/
RewriteCond %{QUERY_STRING} ^val=1234&blah=widget$
RewriteRule .* test.php?val=321&blah=widget [R=301,L]

This is useful if , for example, people are finding you via "old" urls in Google (or if you've changed the url variables you are using). The [R=301,L] bit is important , as this redirects the users browser to the new version of your url (which they can then bookmark).