AltJ.com, the blog

Some geek stuff, some not so geek stuff.

Technology

Using ReWrite rules for URL parameters

So, I was just contacted about a blog post that was accidentally deleted and recreated. Unfortunately, links to the old post had already been sent out. I wanted to use ReWrite to send anyone going to:
http://theblogdomainname.com/?p=376
to:
http://theblogdomainname.com/?p=375

a simple edit to my .htaccess file and viola! it works:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^p=375(.*) [NC]
RewriteRule ^.*$ http://theblogdomainname.com/?p=376%1 [R=301,L]

One nice thing about this is it preserves any parameters following the “p” parameter.  In this case, additional parameters were being used in the URL for tracking.