温馨提示×

根域名怎么跳转301

小新
178
2021-01-27 15:50:45
栏目: 其他

根域名怎么跳转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-8;

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了。

0