网站的域名升级了,需要启用新的域名使用。
但是用户却不知道,还可能使用旧的域名访问网站。
需要把通过旧域名访问的来源,重定向到新的域名。
语法:
#把当前域名的请求全部重定向到新域名www.lnmp.com rewrite / http://www.lnmp.com permanent; #permanent #返回301永久重定向,浏览器地址栏会显示跳转后的URL地址
示例配置:
#shop.lnmp.com的请求全部重定向到www.lnmp.com中
server {
listen 80;
server_name shop.lnmp.com;
rewrite / http://www.lnmp.com permanent; <-*
}
server {
listen 80;
#绑定新域名即可
server_name www.lnmp.com; <--*
root html/tp5shop/public;
index index.php index.html;
access_log logs/shop.lnmp.com_access.log mylogs;
location / {
rewrite /index.html /index.php last;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/218975.html原文链接:https://javaforall.net
