Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have this RedirectMatch rule to move clients on the SSL enabled site while maintaining the path they're trying to access:

Redirectmatch permanent (.*)$1

and it is working perfectly. Now we would like to add an exception for /somepath that should not be redirected. How can I do that?

With mod_rewrite I would add a rewriterule saying "don't rewrite and stop matching", but there isn't such mechanism with redirect. Also, if I trivially reverse the regexp like !(/somepath|/someotherpath) it would no longer get the $1 parameter.

share|improve this question
up vote 1 down vote accepted

Any reason you don't want to use mod_rewrite?

You could mimic the functionality with this:

RewriteCond  %{REQUEST_URI}  !^/(somepath|someotherpath)
RewriteRule  (.*)                       $1                        [R=permanent]
RewriteRule  http://%{SERVER_NAME}(.*)$1  [L]

I hadn't realized Apache uses PCRE. Since it does, you can do this bit of voodoo to do what you want with mod_alias:

RedirectMatch permanent ^/?((?!(thisisfoo|thisisbar)).*)$1

where /thisisfoo and /thisisbar are exceptions to the redirect.

share|improve this answer
mod_rewrite is never the answer to whole-site problems. – adaptr Oct 23 '12 at 12:52
@adaptr: I agree 100%, eventually you get mounds of convoluted match rules, the whole thing becomes a mess. Plus mod_rewrite requires more resources, and executes before all mod_alias declarations. So mod_rewrite is extremely powerful, but flexibility always comes at a cost. Sometimes it's the best tool for the job, but it seems like everyone just copies/pastes mod_rewrite rules for everything. – TechZilla Feb 7 '13 at 17:40

According to the documentation (at, Redirects are proccessed in the order they are encountered. So you would want to put your more restrictive rule first, and then have your catch-all rule at the end.

share|improve this answer
Which works great, assuming your narrowly scoped declaration is a redirect. In this particular question, it's not a redirect, it's an exception to the site-wide redirect. Still a great tip, just not an answer related to the OP. On the other hand, this would make a great comment. – TechZilla Feb 7 '13 at 17:37

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.