php通过htaccess改网页后缀,php – .htaccess没有正确地重定向到www-prefixed页面

我正在尝试重定向没有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

但是,生成的HTML文件是这样的:

301 Moved Permanently

Moved Permanently

The document has moved here.


Apache/2.2.16 (Debian) Server at example.com Port 80

(注意文件之间的地址差异)

有人知道如何解决这个问题(以及它到底是什么原因造成的)?

任何其他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的定义:

ServerAdmin webmaster@localhost

ServerName example.com

ServerAlias example.com www.example.com

DocumentRoot /var/www/example/

Options FollowSymLinks

AllowOverride All

Options Indexes FollowSymLinks MultiViews

AllowOverride All

Order allow,deny

allow from all

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

AllowOverride All

Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch

Order allow,deny

Allow from all

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

编辑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');

它导致完全相同的重定向循环.说真的,到底是什么?有没有人知道可能导致这种情况的原因是什么?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值