2014-03-28 45 views
2

我正在使用drupal htaccess建議的重定向代碼,因爲我希望僅使用www前綴瀏覽我的網頁。壞消息是,顯然,stats.domainname.tld被重定向到www.stats.domainname.tld這是不想要的。如何防止htaccess重定向非www網址,除了那些以特定字符串開頭的網址?

如何更改下面的htaccess重寫規則不這樣做?

# To redirect all users to access the site WITH the 'www.' prefix, 
    # (http://example.com/... will be redirected to http://www.example.com/...) 
    # uncomment the following: 
    RewriteCond %{HTTP_HOST} . 
    RewriteCond %{HTTP_HOST} !^www\. [NC] 
    RewriteRule^http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

回答

2

您的規則改成這樣:

RewriteCond %{HTTP_HOST} ^domainname\.tld$ [NC] 
RewriteRule^http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE] 
+0

有沒有這樣做像這樣的任何不利!'的RewriteCond%{HTTP_HOST} ^(WWW |統計)\。 [NC]' – Alex

+1

沒有真正的缺點,但是如果你設置了另一個子域,明天再次調用它'sub1.domainname.tld',那麼你將不得不將這條規則更新爲:'RewriteCond%{HTTP_HOST}!^ |統計| SUB1)\。 [NC]' – anubhava