【发布时间】:2018-08-21 15:07:31
【问题描述】:
求救是因为我的脑袋已经断了,不知道怎么解决……
我从一个域移动到另一个域,我希望所有链接 301 重定向到新域,但到主页我想添加查询字符串,如 ?from=example.com(仅用于主页)。
https://example.com301 -> https://newdomain.com/?from=example.com
所有其他链接都只是重定向 301,例如 https://newdomain.com$request_uri;
试过了,还是不行
server {
listen 443 ssl;
server_name example.com www.example.com;
location = / {
return 301 https://newdomain.com/?from=example.com;
}
return 301 https://newdomain.com$request_uri;
}
感谢您的帮助
【问题讨论】:
-
发生了什么?
-
curl -I example.com HTTP/1.1 301 永久移动服务器:nginx 日期:2018 年 3 月 13 日星期二 11:40:01 GMT 内容类型:文本/html 内容长度:178 连接: keep-alive 位置:newdomain.com curl -I example.com/some-location/test HTTP/1.1 301 永久移动服务器:nginx 日期:2018 年 3 月 13 日星期二 11:40:22 GMT 内容类型:文本/html 内容长度:178 连接:保活位置:newdomain.com/some-location/test
-
curl -I example.com/ ?顺便说一句,什么版本的 nginx?
-
curl -I example.com HTTP/1.1 301 永久移动服务器:nginx 日期:星期二,2018 年 3 月 13 日 11:50:55 GMT 内容类型:文本/html 内容长度:178 连接:保活位置:newdomain.com
-
我确实要求的是“example.com/”,而不是“example.com”
标签: linux redirect nginx web http-status-code-301