Q:

RewriteRule 301 issue where original URL contains a ? (question mark)

I'm replacing an existing website so the domain is not changing. I do want to use 301 redirects so that bots and search engines will recognize the new pages. I've tried the following but it did not work.
original URL:
http://example.com/index.php?SiteAction=Directions
new URL:
http://example.com/map/
RewriteEngine On
RewriteBase /

#301 redirects using RewriteRule
RewriteRule ^index.php?SiteAction=Directions$ http://example.com/map/ [R=301,L]

The question mark after the index.php seems to completely break my site like that so I've also tried writing it like this, but nothing happens then:
RewriteRule ^index.php(.)SiteAction=Directions$ http://example.com/map/ [R=301,L]

I'm using a Dreamhost PS, if that makes any difference.

A:

You cannot match QUERY_STRING in RewriteRule, you need to RewriteCond %{QUERY_STRING}.
Use this rule instead:
RewriteEngine On

RewriteCond %{QUERY_STRING} ^SiteAction=Directions$ [NC]
#301 redirects using RewriteRule
RewriteRule ^index\.php$ http://example.com/map/? [R=301,L,NC]

