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]
精彩评论