Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Put the code below in subdomain.example.com virtual host section:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com [NC]
RewriteCond %{REQUEST_URI} !/files
RewriteRule ^(.*)$ http://example.com%{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 example.com? –  bogdanvursu Sep 26 '11 at 8:02
    
You can check %{HTTP_HOST}. –  quanta Sep 26 '11 at 8:13

Your Answer

 
discard

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.