2010-06-18 62 views

回答

0

您可以使用重寫模塊移除萬維網。當它在一個子域之前時。通過這種方式,如地址: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> 
0

修改測試解決方案,但僅用於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] 
0

這將做的工作,並與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 

但是你不需要索引。