开发者

Adding "www" with mod_rewrite [duplicate]

开发者 https://www.devze.com 2023-04-10 01:06 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: 301 redirect non-www to www not always working
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

精彩评论

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