0

可能重复:
301 将非 www 重定向到 www 并不总是有效

我有一个网站,可以使用“www”和不使用“www”(例如www.example.comexample.com)访问它。如果 URL 中没有“www”,则 mod_rewrite 用于重定向到 www.example.com。

但是,如果我去example.com/something.html,它会被重定向到www.example.comsomething.html被截断)。

目前,我的规则是:

<VirtualHost *:80>
    ServerName example.com
    RewriteEngine On
    RewriteRule /.* http://www.example.com [R]
</VirtualHost>

使重写递归和使example.com/something.html重定向到www.example.com/something.html的最简单方法是什么

4

1 回答 1

-1
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
于 2011-11-28T14:45:25.197 回答