开发者

Adding "www" with mod_rewrite [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

301 redirect non-www to www not always working

I have a web site and it is possible to access it with both "www" and without "www" (e.g. www.example.com and example.co开发者_运维技巧m). mod_rewrite is used to redirect to www.example.com if there is no "www" in URL.

But, if I go to example.com/something.html, it gets redirected to www.example.com (something.html gets truncated).

Currently, the rule I have is:

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

What is the easiest way to make rewriting recursive and to make example.com/something.html redirect to www.example.com/something.html


RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜