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

I need to redirect all the traffic from


With 'folder' being a specific folder, of course. I've tried this:

RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$
RewriteRule ^.*$ [L]

But it doesn't work. What's wrong?

share|improve this question
up vote 5 down vote accepted

Try this:

RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$
RewriteRule ^/$ [R,L]

The only change I made was to add R in the options after the RewriteRule. That option tells Apache to do a 302 redirect. You can use R=301 if you want a permanent redirect.

share|improve this answer
The URL is redirected, but it gives the following error: "Error 310 (net::ERR_TOO_MANY_REDIRECTS)" in Chrome under Mac OS X. The page is blank, apart from that error :( – javipas Nov 21 '11 at 15:48
I have edited my answer. The first part of the RewriteRule is now ^/$ so that it doesn't end up in a redirect loop. I'm surprised I didn't notice that when I first answered. – Ladadadada Nov 21 '11 at 15:53
That did it. Would you be so kind to explain me why it was wrong with the past version? Thanks! – javipas Nov 21 '11 at 18:57
A RewriteRule is made up of three parts separated by spaces: the pattern, the substitute and the options. The pattern is a regex that is matched against the request URI. In the first version, the pattern was ^.*$ which as a regex matches any URI. Any URI you requested would always redirect to /folder/, even if you requested /folder/, it would still send a redirect response pointing to /folder/. In the second version, it now only matches exactly /. The Apache rewrite guide is highly recommended. – Ladadadada Nov 21 '11 at 19:39
Fantastic explanation, I'll read the rewrite guide, thanks for the comment (I've written this while singing your name :) ) – javipas Nov 22 '11 at 11: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.