开发者

Am I using mod rewrite right?

RewriteCond %{SERVER_NAME} ^([^.]+\.[^.]+)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]

I want to rewrite mysite.com to www.mysite.com when no subdomain is indicated. If for 开发者_如何学运维example someone requests test.mysite.com then it will remain test.mysite.com, but mysite.com alone will be redirected to www.mysite.com.

Just wanted to make sure that what I have now is right and there are no possible problems in the condition and rule that I'm using. Solution above was recommended by one of the fellow SO users, but I replaced {HTTP_HOST} with {SERVER_NAME}


it should do the trick, if you do not have multi subdomain like test.test.mysite.com

Anywho, regarding the HTTP_HOST vs SERVRE_NAME, check HTTP_HOST vs. SERVER_NAME

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜