根域名怎样跳转301
根域名做301跳转的方法:
1.在域名公司,将根域名解析到目标服务器ip地址。
2.在nginx新建xxx.com.conf的vhost文件,内容以下:
vi xxx.com.conf
server {
listen 80;
server_name xxx.com;
rewrite ^(.*)$ http://www.xxx.com$1 permanent;
}
server {
listen 443 ssl http2;
server_name xxx.com;
rewrite ^(.*)$ https://www.xxx.com$1 permanent;
ssl_certificate certs/Nginx/1_www.xxx.com_bundle.crt;
ssl_certificate_key certs/Nginx/2_www.xxx.com.key;#由于这两个命令的默许值已好几次产生了改变,因此不建议显性定义,除非有需要额外定义的值
# ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
# ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
charset utf⑻;
access_log logs/localhost.access.log main;
error_log logs/localhost.error.log warn;
root html;
index index.php index.html index.htm;
location / {
……
}
}
3.这样在浏览器访问xxx.com,就会自动跳转到www.xxx.com了。
本文来源:https://www.yuntue.com/post/77263.html | 云服务器网,转载请注明出处!