开发者

Having trouble with mod rewrite non www to www

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜