开发者

Having trouble with mod rewrite non www to www

开发者 https://www.devze.com 2023-02-11 22:25 出处:网络
Can anyone help me with this: RewriteCond %{HTTP_HOST} !^www\\.(.*)$ [NC] RewriteRule ^(.*)$ http://www.$1 [R=301,L]

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

精彩评论

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