.htaccess for Apache
重定向 xzy.one 到 www.xzy.one,请在.htaccess 中加入下列代码:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.xzy.one$ [NC]
RewriteRule ^(.*)$ https://www.xzy.one/$1 [L,R=301]
重定向 www.xzy.one 到 xzy.one,请在.htaccess 文件中加入下列代码:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^xzy.one$ [NC]
RewriteRule ^(.*)$ https://xzy.one/$1 [L,R=301]
重定向 laoyuming.com 到 www.xinyuing.com,请在.htaccess 文件中加入下列代码:
RewriteEngine On
RewriteCond %{HTTP_HOST} !laoyuming.com$ [NC]
RewriteRule ^(.*)$ https://www.xinyuming.com/$1 [L,R=301]
重定向 laoyuming.com 到 xinyuing.com,请在.htaccess 文件中加入下列代码:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !laoyuming.com$ [NC]
RewriteRule ^(.*)$ https://xinyuming.com/$1 [L,R=301]
不同域名下,用 301 将绑定的其他域名重定向到主域名,例如将 xzy.space 和 www.xzy.es 统一为 www.xzy.one
RewriteEngine on
RewriteCond %{HTTP_HOST} ^xzy.space$ [OR]
RewriteCond %{HTTP_HOST} ^www.xzy.es$
RewriteRule ^(.*)$ https://www.xzy.one/$1 [R=301,L]
还有一些 SEOer 觉得 index.php 和 index.html 这样的也要重定向 www.xzy.one,以防止权重分散。
RewriteEngine on
RewriteRule ^index.php$ https://www.xzy.one/ [R=301,L]
二、 301 永久重定向设置 Nginx 服务器 conf 规则篇
.conf for Nginx
正常的话 conf 一般前面部分是显示是这样的:
server{
listen 80;
server_name www.xzy.one xzy.one;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/www.xzy.one;
}
现在你需要将一段 Nginx 服务器 conf 的 301 永久重定向规则添加在 server_name www.xzy.one xzy.one; 下面:
if ($host != 'www.xzy.one' ) {
rewrite ^/(.*)$ https://www.xzy.one/$1 permanent;
}
最后代码 conf 文件前面的部分应该是显示这样的:
server{
listen 80;
server_name www.xzy.one xzy.one;
if ($host != 'www.xzy.one' ) {
rewrite ^/(.*)$ https://www.xzy.one/$1 permanent;
}
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/www.xzy.one;
}
上传该文件覆盖,或者在 SSH 直接编辑保存。最后执行下列命令,重载配置,完成生效。