[v_notice]简单高效的在nginx和apache环境下把不带WWW的域名301到带WWW域名上的重定向。[/v_notice]
[v_act]nginx域名301重定向有三种方法:[/v_act]
原生法 nginx高版本支持:
server { server_name weizhushou.net; return 301 https://www.weiboke.top$request_uri; }
重写法 nginx通用支持:
server { server_name weizhushou.net; rewrite ^(.*) https://www.weiboke.top$1 permanent; }
判断重写法:
if ($host != 'www.weizhushou.net'){ rewrite ^/(.*)$ https://www.weiboke.top/$1 permanent; }
[v_act]Apache域名301重定向 .htaccess[/v_act]
方法一:
Options +FollowSymLinks RewriteEngine on RewriteRule (.*) https://www.weiboke.top/$1 [R=301,L]
方法二:
RewriteEngine On RewriteCond %{HTTP_HOST} ^weizhushou.net/ [NC] RewriteRule ^(.*)$ https://www.weiboke.top/$1 [L,R=301]