0

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

bogdan
  • 155
  • 1
  • 8

1 Answers1

2

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]
bogdan
  • 155
  • 1
  • 8
quanta
  • 51,413
  • 19
  • 159
  • 217
  • 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? – bogdan Sep 26 '11 at 08:02
  • You can check `%{HTTP_HOST}`. – quanta Sep 26 '11 at 08:13