我有两个服务器上安装的Web应用程序。 在其中一台服务器上,当我访问主页时,在浏览器中出现“错误代码:ERR_TOO_MANY_REDIRECTS”错误,而另一台服务器正常工作。 两台服务器都运行apache 2.4。
Apacheconfiguration的哪一部分与redirect规则有关? 我应该在哪里寻找两种configuration之间的差异?
以防万一,这里是htaccess文件:
<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>
我经常发现这种不同的行为可以归因于configuration上的差异。 为此,我编写了一个脚本( httpd-dump-config )来压缩httpd.conf,这样我就可以对它进行区分,以便我可以审查群集节点之间或环境之间的差异(即使通过SSH)
它不会检查.htaccess文件,但它仍然可以帮助find容易被忽略的.htaccess文件:
find $(httpd-dump-config | grep -i DocumentRoot | awk '{print $2}') -type f -name '.htaccess' -print
我不build议用ssh和diff来尝试上面的代码(因为转义会杀了你)
比较两台机器的非.htaccessconfiguration:
diff <(httpd-dump-config) \ <(ssh webserverB.dom httpd-dump-config)
也有可能从代码发出redirect(比如PHP发送一个位置标题,比如它经常散布在我见过的很多PHP中)。
你在所有浏览器上都有这个错误吗?
每次我遇到这个问题,总是在一个特定的浏览器或由于url奇怪的结果微小的故障。
重写规则通常是这样的
RewriteEngine on RewriteCond /your/docroot/%{REQUEST_FILENAME} !-f RewriteRule ^(.+) http://webserverB.dom/$**1
“这里的问题是,这只适用于DocumentRoot中的页面,虽然你可以添加更多的条件(例如也可以处理homedirs等),但是还有更好的变体:”
RewriteEngine on RewriteCond %{REQUEST_URI} !-U RewriteRule ^(.+) http://webserverB.dom/$1**
“这使用了mod_rewrite的URL预览function,其结果是,这将适用于所有types的URL,并且是一种安全的方式,但是它会对web服务器产生性能影响,因为对于每个请求,都会有一个内部子请求所以,如果你的web服务器运行在一个强大的CPU上,使用这个,如果它是一个很慢的机器,使用第一种方法或更好的ErrorDocument CGI脚本。
您也可以查看扩展redirect 。