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.

I am getting a "too many redirects" error from the following two .htaccess files.

.htaccess on domain 1

Redirect 301 / http://www.domain2.com/

.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
add comment

2 Answers

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 "badsite1.com" or "badsite2.com" also a part of your domain name? For example if the literal "badsite1.com" is "fred.com" and your domain is "myfred.com" 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 http://www.domain2.com/forum/? 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 curl.haxx.se/download.html. 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
1  
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
show 8 more comments

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
add comment

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.