我正在尝试重定向没有www的网址.到www.version(example.com到www.example.com).
我常用
我常用
RewriteCond %{HTTP_HOST} ^example\.com [nc] RewriteRule (.*) http://www.example.com/$1 [R=301,L]
这适用于我所有的其他项目.但是在此特定站点上,它以重定向循环结束.这是奇怪的部分:我试图卷曲非www版本以查看它使用的发送标头
curl –get http://example.com –dump-header domain.header> domain.html.
头文件看起来像这样:
HTTP/1.1 301 Moved Permanently Date: Mon,06 Jun 2011 14:45:16 GMT Server: Apache/2.2.16 (Debian) Location: http://example.com/ Vary: Accept-Encoding Content-Length: 310 Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>301 Moved Permanently</title> </head><body> <h1>Moved Permanently</h1> <p>The document has moved <a href="http://www.example.com/">here</a>.</p> <hr> <address>Apache/2.2.16 (Debian) Server at example.com Port 80</address> </body></html>
(注意文件之间的地址差异)
有人知道如何解决这个问题(以及它到底是什么原因造成的)?
任何其他URL重写指令都可以正常工作.
编辑:重写日志包含这个:(该网站被很多人访问,所以重写日志得到很长时间,我不是100%肯定,如果这是正确的部分)
192.168.1.221 - - [06/Jun/2011:17:49:32 +0200] [example.com/sid#b797f948][rid#b7d2c1c8/initial] (3) [perdir /var/www/oup/81/] strip per-dir prefix: /var/www/oup/81/ -> 192.168.1.221 - - [06/Jun/2011:17:49:32 +0200] [example.com/sid#b797f948][rid#b7d2c1c8/initial] (3) [perdir /var/www/oup/81/] applying pattern '(.*)' to uri '' 192.168.1.221 - - [06/Jun/2011:17:49:32 +0200] [example.com/sid#b797f948][rid#b7d2c1c8/initial] (2) [perdir /var/www/oup/81/] rewrite '' -> 'http://www.example.com/' 192.168.1.221 - - [06/Jun/2011:17:49:32 +0200] [example.com/sid#b797f948][rid#b7d2c1c8/initial] (2) [perdir /var/www/oup/81/] explicitly forcing redirect with http://www.example.com/ 192.168.1.221 - - [06/Jun/2011:17:49:32 +0200] [example.com/sid#b797f948][rid#b7d2c1c8/initial] (1) [perdir /var/www/oup/81/] escaping http://www.example.com/ for redirect 192.168.1.221 - - [06/Jun/2011:17:49:32 +0200] [example.com/sid#b797f948][rid#b7d2c1c8/initial] (1) [perdir /var/www/oup/81/] redirect to http://www.example.com/ [REDIRECT/301]
访问日志行(可能是正确的):
192.168.1.221 - - [06/Jun/2011:17:49:32 +0200] "GET / HTTP/1.1" 301 555 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.24 (KHTML,like Gecko) Chrome/11.0.696.77 Safari/534.24"
virtualhost的定义:
<VirtualHost *:80> ServerAdmin webmaster@localhost ServerName example.com ServerAlias example.com www.example.com DocumentRoot /var/www/example/ <Directory /> Options FollowSymLinks AllowOverride All </Directory> <Directory /var/www/example/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride All Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug,info,notice,warn,error,crit,# alert,emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
编辑2:好吧,我只是想通了如果我这样做(辞职并尝试重定向,没有.htaccess):
//if clause determining that we're running on example.com and not www.example.com header('HTTP/1.1 301 Moved Permanently'); header('Location: http://www.example.com' . $_SERVER['REQUEST_URI']); header('Connection: close');
它导致完全相同的重定向循环.说真的,到底是什么?有没有人知道可能导致这种情况的原因是什么?
让我感到奇怪的是位置:CURL报道的http://domain.cz/标题行.您永远不会重定向到该域.重定向日志也不包含任何提及.
不知何故,在modrewrite执行其操作之后,Location标头似乎已被更改,并且由于您尝试使用PHP更改标头,因此在处理请求后,Location标头显然已更改.我能想到的唯一解释是你正在某处用mod_header修改位置标题.
如果您在某处找到与此类似的行,您是否检查了所有配置文件(httpd.conf,包含的.conf文件和.htaccess文件):
Header set Location (...)
要么
Header edit Location (...)