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 am getting a "too many redirects" error from the following two .htaccess files.

.htaccess on domain 1

Redirect 301 /

.htaccess on domain 2

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [L,R]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /forum/ [L,R]

RedirectMatch permanent ^/$ /forum/

# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} badsite1\.com [NC,OR]
RewriteCond %{HTTP_REFERER} badsite2\.com [NC]
RewriteRule .* - [F] 

Anyone know the reason for the too many redirects error?

share|improve this question
Where are you being redirected to? /forum/, maybe? What content is in that directory? – Shane Madden Jul 22 '12 at 17:34
Without the last 3 lines (ReWriteRule .* - [F]) everything redirects succesfully to /forum/ on domain 2. But as soon as I include that code, the too many redirects error occurs. – Knocks X Jul 22 '12 at 17:47
That doesn't make a lot of sense. Are you absolutely certain that that's the only thing you're modifying and not also, say, that Options directive? – Shane Madden Jul 22 '12 at 17:50
Correct. Right now the site is functioning, but only because the last line has been removed. The downside is those malicious sites are able to sendi me garbage traffic this way. – Knocks X Jul 22 '12 at 17:54
Ok, then we're back to needing to figure out where the redirect is sending you. As John's saying, let's get some curl output. – Shane Madden Jul 22 '12 at 17:58

Does the directory "/forum/" exist on your site in domain2? If not, then following RewriteCond (Rewrite conditions) & RewriteRule will always result in redirecting to /forum/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /forum/ [L,R]

That would result in an infinite redirect loop resulting in a too many redirects error.

From your additional comments you say that the following three lines of code cause the redirect loop:

RewriteCond %{HTTP_REFERER} badsite1\.com [NC,OR]
RewriteCond %{HTTP_REFERER} badsite2\.com [NC]
RewriteRule .* - [F] 

By any chance is "" or "" also a part of your domain name? For example if the literal "" is "" and your domain is "" then this condition will match your site's requests.

share|improve this answer
Yes, in fact the /forum/ directory is the only active part of the site on domain2, so I'm sending all visitors there. The weird part is, everything works fine until I add the last 3 lines (deflecting spam domain referrals). – Knocks X Jul 22 '12 at 17:41
What do you get if you perform curl --verbose Do you get an HTTP 200 OK or something else? – HeatfanJohn Jul 22 '12 at 17:44
I'm not familiar with curl and I only have a Windows laptop at my disposal. Does curl run locally or serverside? – Knocks X Jul 22 '12 at 17:46
You can run curl from a laptop. You can download it from Pick the Windows 32 bit generic version. I'm also looking into what your RedirectMatch permanent ^/$ /forum/ rule does. That may be the culprit for the infinite redirects. – HeatfanJohn Jul 22 '12 at 17:49
Just to clean up this question. When the site allows you, you should post your own answer saying that everything just started working as expected after you replaced your .htaccess file back to the contents shown in your question. – HeatfanJohn Jul 22 '12 at 18:51

It turns out the code was fine. It's possible that a cached copy of perhaps incorrect code was being loaded and was causing the error.

share|improve this answer

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.