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

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

I'm looking for the rewrite rule for mod_rewrite in Apache so that when asking for a specific subdirectory, it and all its contents gets redirected to another location.

I currently have the following:

    RewriteEngine  on
    RewriteRule    ^/SUBDIRECTORY(/.*)?  /another/location

But this only manages to redirect /SUBDIRECTORY requests to the desired location, while all others (like (/SUBDIRECTORY/ , /SUBDIRECTORY/anything/else ) gets me an error telling me that the redirection is not valid... The error is


as if the redirections loops themselves...

any ideas?


share|improve this question
up vote 1 down vote accepted

Maybe try it without the question mark?

RewriteRule ^/somepath(.*) /another/location

Edit: I wonder if its just hitting some sort of loop, maybe try external redirection

RewriteRule    ^/SUBDIRECTORY(/.*)  /another/location [R]
share|improve this answer
nope... this throws me the same error as before... BTW I'm using Apache 2.2, and if I add a RewriteLog it doesn't writes anything to it :/ neither to error_log ... The error is a 310 Error (to many redirections) – Javier Novoa C. Jan 12 '11 at 19:29
that's it! the R flag fixed the problem... Thanks! – Javier Novoa C. Jan 12 '11 at 23:03

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.