(Apache) RedirectMatch regex to match all directories except those in my list
Posted
by
dotben
on Server Fault
See other posts from Server Fault
or by dotben
Published on 2011-02-10T05:39:02Z
Indexed on
2011/02/10
7:27 UTC
Read the original article
Hit count: 559
I need to 301 redirect all requests coming in for requests to http//server.com to be redirected to http//newserver.com unless the request is for an arbitary list of directories we are maintaining on the legacy server (eg server.com/foo or server.com/bar)
I'm having a hard time working out how best to set this up and the regexs.
EG, I need:
- http//server.com/page1 redirect to http//newserver.com/page1
- http//server.com/dir1/page2 redirect to http//newserver.com/dir1/page2
- http//server.com/foo to load as normal
- http//server.com/bar/baz.html to load as normal
... because 'foo' and 'bar' are in my list of legacy dirs.
I'm wondering if the way to do this is to some how catch the matches in my list and then redirect anything else as a wildcard over to the new server -- but I can't make it work.
Can anyone help me with some regex and rewrites for those please?
Thanks
(apologies for fudging the http:// in the urls, ServerFault thinks I'm posting hyperlinks and won't otherwise let me post this)
© Server Fault or respective owner