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

Can anyone help me achieve a redirect in Apache from to for all URLs, EXCEPT the ones starting with "files/"? Thank you

share|improve this question
up vote 2 down vote accepted

Put the code below in virtual host section:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com [NC]
RewriteCond %{REQUEST_URI} !/files
RewriteRule ^(.*)${REQUEST_URI} [R=301,L]
share|improve this answer
Thanks for your answer. The problem is that both subdomains have the same document root. Is there any way I could prevent infinite redirection for the – bogdanvursu Sep 26 '11 at 8:02
You can check %{HTTP_HOST}. – quanta Sep 26 '11 at 8:13

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.