1

I have a web app installed on two servers. On one of the servers, when I'm accessing the homepage I get the "Error code: ERR_TOO_MANY_REDIRECTS" error in the browser while on the other one everything works fine. Both servers are running apache 2.4.

What part of the apache configuration is related to the redirect rules? Where should I look for differences between the two configurations?

Just in case, here is the htaccess file:

<IfModule mod_rewrite.c>
  Options +FollowSymLinks
  RewriteEngine On

  # Get rid of index.php
  RewriteCond %{REQUEST_URI} /index\.php
  RewriteRule (.*) index.php?rewrite=2 [L,QSA]

  # Rewrite all directory-looking urls
  RewriteCond %{REQUEST_URI} /index.php/$
  RewriteRule (.*) index.php?rewrite=1 [L,QSA]

  # Try to route missing files
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} public\/ [OR]
  RewriteCond %{REQUEST_FILENAME} \.(jpg|gif|png|ico|flv|htm|html|php|css|js)$
  RewriteRule . - [L]

  # If the file doesn't exist, rewrite to index
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?rewrite=1 [L,QSA]

</IfModule>

# sends requests /index.php/path/to/module/ to "index.php"
# AcceptPathInfo On

# @todo This may not be effective in some cases
FileETag Size

<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</IfModule>
4
  • Can you issue a diff of both files using the command: diff -y file-from-server1 file-from-server2 ? – fgbreel May 11 '15 at 15:30
  • Could you post the response-headers from both servers when you request the resource with curl? Also, are the versions of PHP on both servers the same and is the code (and database perhaps) 100% the same? – gnur May 13 '15 at 12:57
  • What did you try? – 030 May 13 '15 at 15:55
  • 1
    I would suspect the URL rewriting to index here. Rewriting a URL is not the same as a redirect, which is an HTTP response (see e.g. weblogs.asp.net/owscott/…). If I were you, I'd take a look at the Apache access.log and scan for HTTP 3xx responses. The URL that is logged there is most likely the culprit. The cause for the 3xx response lies likely how the webapp handles missing or broken/corrupt files. – akaasjager May 16 '15 at 19:55
4
+25

I often find such divergent behaviour can be attributed to differences in configuration. For that, I wrote a script (httpd-dump-config) to flatten httpd.conf so I could diff it so I could audit for such differences between cluster nodes or between environments (even over SSH)

It won't check .htaccess files though, but it can still help to find easily overlooked .htaccess files:

find $(httpd-dump-config | grep -i DocumentRoot | awk '{print $2}') -type f -name '.htaccess' -print

I don't recommend trying the above with ssh&diff as shown below (because the escaping will kill you)

Comparing the two machines non-.htaccess configuration:

diff <(httpd-dump-config) \
     <(ssh webserverB.dom httpd-dump-config)

There is also the possibility that a redirect could be issued from the code (like PHP sending a Location header; such as it often littered or otherwise tucked away in a lot of PHP I've seen).

0

Are you having this error on all browsers?

Everytime I encounter this problem is always either a tiny glitch in one particular browser or a result of wierd URL.


Rewrite rules are normally this

RewriteEngine on
RewriteCond   /your/docroot/%{REQUEST_FILENAME} !-f
RewriteRule   ^(.+)                             http://webserverB.dom/$**1

"The problem here is that this will only work for pages inside the DocumentRoot. While you can add more Conditions (for instance to also handle homedirs, etc.) there is better variant:"

RewriteEngine on
RewriteCond   %{REQUEST_URI} !-U
RewriteRule   ^(.+)          http://webserverB.dom/$1**

"This uses the URL look-ahead feature of mod_rewrite. The result is that this will work for all types of URLs and is a safe way. But it does a performance impact on the webserver, because for every request there is one more internal subrequest. So, if your webserver runs on a powerful CPU, use this one. If it is a slow machine, use the first approach or better a ErrorDocument CGI-script."

You can also look into extended redirection.

http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.