views:

566

answers:

1

I recently changed my CMS, and want to rewrite some of my URLs to match the new URL/query string parameter format.

The old URL was:

http://www.mysite.com/search.cgi?tag=foo&blog_id=bar&other=baz

The new URL should be:

http://www.mysite.com/?s=foo

In other words, there were several query string parameters in the old format, but I only care to rewrite the tag param to s while keeping the same value. The other parameters should be discarded. Of course the order of the parameters shouldn't matter. It also shouldn't matter whether tag is the only parameter or not.

Any ideas?

+2  A: 
Lorenzo V.
So the %1 in RewriteRule reflects the regular expression match in RewriteCond?
lupefiasco
Yes, %1 is used to refer to a group in a RewriteCond, while $1 is used to refer to a group in a RewriteRule directive.
Lorenzo V.
And how would I set up my RewriteUrl specifically to map the /search.cgi?... part to /?...
lupefiasco
Also, if I wanted this configured as a Redirect instead of a Rewrite, what would change?
lupefiasco
To make a Redirect put R=<HTTP Status Code> after the [L]ast rule: i.e.: `RewriteRule %{REQUEST_URI} %{REQUEST_URI}?%1 [L,R=302]`. You can find a complete list of HTTP status codes here: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html (you will have to use ones from the 300-307 range). It is common practice to use either 301 or 302 status codes.
Lorenzo V.
Lorenzo V.