我有問題,但有許多子域:如需要刪除從二級子域名WWW一般在Apache中(使用重寫)
sub1.domain.com和new.domain.com和xsub.domain.com還有很多更多這樣的。
如何用一條通用規則從這些網站的前面刪除www。
E.g.如果有人類型www..domain.com或http://www ..domain.com將其更改爲
HTTP://.domain.com
感謝
我有問題,但有許多子域:如需要刪除從二級子域名WWW一般在Apache中(使用重寫)
sub1.domain.com和new.domain.com和xsub.domain.com還有很多更多這樣的。
如何用一條通用規則從這些網站的前面刪除www。
E.g.如果有人類型www..domain.com或http://www ..domain.com將其更改爲
HTTP://.domain.com
感謝
您可以使用重寫模塊移除萬維網。當它在一個子域之前時。通過這種方式,如地址:www.sub1.domain.com將被重定向到sub1.domain.com:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase/
RewriteCond %{HTTP_HOST} !www.domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,NC,L]
</IfModule>
修改測試解決方案,但僅用於HTTP。
#Allow domain of the form www.domain.com
RewriteCond %{HTTP_HOST} !^www\.([^\..]*)\.([^\..]*)$ [NC]
#Otherwise any other form must be rewritten to remove www
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
#Substitue the complete domain using group %1 in the parentheses of the above condition
RewriteRule ^(.*)$ http://%1/$1 [R=301,NC,L]
這將做的工作,並與HTTP返回://
RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule ^(.*) http://%1/$1 [R,L]
對於HTTPS,只是添加了S,像這樣:
RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule ^(.*) https://%1/$1 [R,L]
注意,這可能是在httpd.conf中也是如此。使用.htaccess是流行的,但實際上減慢了網站,特別是如果有嵌套的目錄。
你需要:
Options +FollowSymLinks
但是你不需要索引。