方法一:在网站根目录下创建 .htaccess 文件。添加如下规则:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^zhifou123.com$ [NC]
RewriteRule ^(.*)$ http://www.zhifou123.com/$1 [R=301,L]
</IfModule>
方法2 Linux主机(Nginx环境适用)
通常在 /usr/local/nginx/conf/目录下可以找到用nginx.conf 此文件
在server 里只需要添加此部分,并且更改其中的域名:
if ( $host != 'www.xxxx.com' )
{
rewrite ^/(.*)$http://www.xxxx.com/$1 permanent;
}
然后重启nginx 命令如下几个:
/usr/local/nginx/sbin/nginx -s reload
ps -ef|grep nginx
service nginx restart
原文链接:https://blog.csdn.net/LQZ8888/article/details/99960941