在wordpress站点中,如何将站点的非www版本重定向到www版本以删除重复内容
将站点的非WWW版本重定向到WWW
2 个回复
SO网友:Eugene Manuilov
您需要在中设置它。htaccess文件,它应该如下所示:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^yourdomain\\.com$
RewriteRule (.*) http://www.yourdomain.com/$1 [L,R=301]
RewriteRule ^index\\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
SO网友:Geert
此代码与Eugene的代码类似,但它会将任何不是您的主域且带有“www”的域重定向到正确的地址。如果您有多个顶级域,那么这很方便。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# These are the lines that do the trick
RewriteCond %{HTTP_HOST} !^www\\.yourdomain\\.com$
RewriteRule .* http://www.yourdomain.com/$0 [L,R=301]
</IfModule>
结束