Can anyone help me with this:
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.$1 [R=301,L]
What I am trying to do is create a rewrite rule that sends you to the www version of a site if you try to connect using the non www version.
The condition works but the rules doesn't, it sends me to http:// Can anyone suggest hoe I can fix this. I was expecting $1 = everything in the condition above between ^ and $ Tha开发者_StackOverflownks
Don't use HTTP_HOST
, it's evil.
Do this:
RewriteCond %{SERVER_NAME} !^www\. [NC]
RewriteCond %{SERVER_NAME} (.*)
RewriteRule (.*) http://www.%1/$1 [R=301,L]
Where %1
matches the grouping from a previous RewriteCond
.
精彩评论