小编cyp*_*her的帖子

.htaccess 无法正确重定向到以 www 为前缀的页面

我正在尝试重定向没有 www 的 url。到 www.version(example.com 到 www.example.com)。我用通常的

RewriteCond %{HTTP_HOST} ^example\.com [nc]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
Run Code Online (Sandbox Code Playgroud)

这适用于我所有的其他项目。但是,在这个特定站点上,它以重定向循环结束。这是奇怪的部分:我试图卷曲非 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
Run Code Online (Sandbox Code Playgroud)

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

<!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> …
Run Code Online (Sandbox Code Playgroud)

php mod-rewrite .htaccess http-headers apache-2.2

9
推荐指数
1
解决办法
1838
查看次数

标签 统计

.htaccess ×1

apache-2.2 ×1

http-headers ×1

mod-rewrite ×1

php ×1