如果您已经添加了伪静态规则,直接在.htaccess
文件添加
# 带 www 的跳转到不带的
RewriteCond %{HTTP_HOST} ^www.moobei.com$
RewriteRule ^(.*)$ http://moobei.com/$1 [R=301,L]
或者
# 不带 www 的跳转到带的
RewriteCond %{HTTP_HOST} ^moobei.com$
RewriteRule ^(.*)$ http://www.moobei.com/$1 [R=301,L]
如果你使用了https,可以用如下规则:
所有链接均跳转到https不带WWW的域名
RewriteCond %{HTTP_HOST} ^www.todsay.com$ [NC]
RewriteRule ^(.*)$ https://todsay.com/$1 [R=301,L]
RewriteCond %{HTTP:From-Https} !^on$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://todsay.com/$1 [R=301,L]
所有链接均跳转到https带WWW的域名
RewriteCond %{HTTP_HOST} ^todsay.com$ [NC]
RewriteRule ^(.*)$ https://www.todsay.com/$1 [R=301,L]
RewriteCond %{HTTP:From-Https} !^on$ [NC]
RewriteCond %{HTTP_HOST} ^(www)?.todsay.com$ [NC]
RewriteRule ^(.*)$ https://www.todsay.com/$1 [R=301,L]