Scratching my head on this. I have an old URL:
http://myserver/blog/archive?openview&type=Category&key=Demo
and a new URL
http://myserver/blog/categories/Demo
I'm trying to get a rewrite rule for this. I thought it would be:
^/blog/archive\?openview&type=Category&key=(.*) /blog/categories/$1.html [NC,R=301,L]
But that doesn't do anything. I tried the URL and rule (replace the ? with /):
http://myserver/blog/archive/openview&type=Category&key=Demo
^/blog/archive/openview&type=Category&key=(.*) /blog/categories/$1.html [NC,R=301,L]
And that works as expected. So I'm a bit dumbfolded how to handle the ? for matching in the old URL. All the samples I found describe the opposite case. Sending the "pretty" URL to the ugly one. In my case the "ugly" URL is what people in the past had bookmarked and I want to make sure they get to the new data properly
A little thinking (and reading the documentation) later:
The mod_rewrite matches use the location part of the URL only. The "?" marks the end of the location and the beginning of the parameters (a.k.a QueryString). Once I realized that, it was just a Google away.
So to transform correctly you need a rewrite condition:
Works like a charm