Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I need to 301 redirect all requests coming in for requests to to be redirected to unless the request is for an arbitrary list of directories we are maintaining on the legacy server (eg or

I'm having a hard time working out how best to set this up and the regexs.

EG, I need:

  • to redirect to
  • to redirect to
  • to load as normal
  • 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?


share|improve this question

1 Answer 1

You could try

RewriteCond %{REQUEST_URI} !^(/foo/|/bar/).*
RewriteRule ^(.*)$$1 [R]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.