如何添加子域名在.htaccess和URL强制WWW
问题描述:
我有以下的code强制WWW的网址
I have the following code to force WWW in url
rewriteCond %{HTTP_HOST} !^www.example.com [NC]
rewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
我想添加一个子域max.example并参考www.example.com/update/max~~V目录 如果我不添加任何规则,max.example.com会重定向到www.example.com/update/max~~V。如果我删除力WWW的URL它的工作原理。但我仍然需要在URL强制WWW。如何编写规则?
I want to add a subdomain max.example and refer to www.example.com/update/max directory If I do not add any rule, max.example.com will redirect to www.example.com/update/max . If I remove force WWW in url it works. But I still need force WWW in url. How to write the rule?
谢谢!
答
更改您的规则如下:
Change your rule to this:
RewriteCond %{HTTP_HOST} !^(www|max)\.example\.com$ [NC]
RewriteRule ^ http://www.example.com%{REQUEST_URI} [R=301,L]