I have a few messy old URLs like...
http://www.example.com/bunch.of/unneeded/crap?opendocument&part=1
http://www.example.com/bunch.of/unneeded/crap?opendocument&part=2
...that I want to redirect to the newer, cleaner form...
http://www.example.com/page.php/welcome
http://www.example.com/page.php/prices
I understand I can redirect one page to another with a simple redirect i.e.
Redirect 301 /bunch.of/unneeded/crap http://www.example.com/page.php
But the source page doesn't change, only it's GET vars. I can't figure out how to base the redirect on the value of these GET variables. Can anybody help pls!? I'm fairly handy with the old regexes so I can have a pop at using mod-rewrite if I have to but I'm not clear on the syntax for rewriting GET vars and I'd prefer to avoid the performance hit and use the cleaner Redirect directive. Is there a way? and if not can anyone clue me in as to the right mod-rewrite syntax pls?
Cheers,
Roger.
In summary, you could use
RedirectMatch
with a regex that will match the full URL, including query string. That will let you rearrange parts of the URL, but if you have to do conversions like "opendocument&part=1" to "welcome" (where the new URL is completely different from the original one), you might need aRewriteMap
- or perhaps better, just send all URLs topage.php
and parse the query string in PHP.EDIT: If it's just a few URLs you want to redirect, you could probably write out individual rules like
@Jack Ross
The ? will prevent the url the user is sent to from having the same query string as the origin page.
As the parameters in the URL query may have an arbitrary order, you need to use a either one
RewriteCond
directive for every parameter to check or for every possible permutiation.Here’s an example with a
RewriteCond
directive for each parameter:But as you can see, this may get a mess.
So a better approach might be to use a
RewriteMap
. The easiest would be a plain text file with key and value pairs:To define your map, write the following directive in your server or virual host configuration (this directive is not allowed in per-directory context):
Then you would just need one rule: