在Nginx中重定向两个长域URLS的最佳方法是什么,我想在两个域之间配置一个重定向,如下所示:
我相信这之前有人问过,但我找不到一个可行的解决方案。
original link:
https://qwerty.test.com/education/7/abc-science
New link
https://www.test.com/education/7/abc-science我试过这样做:
server {
listen 80;
listen 443 ssl;
server_name qwerty.test.com/education/7/abc-scienc;
return 301 $scheme://www.test.com/education/7/abc-science$request_uri;
}仍然会收到一些错误
nginx: [warn] server name "education/7/abc-scienc
" has suspicious symbols in /etc/nginx/conf.d/redirect.conf:9
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful重复问题如下:https://stackoverflow.com/questions/74101316/long-url-diffrent-domain-redirect-nginx-issue
这些变化对我有用吗?
server {
listen 80;
server_name www.test.com;
#old url
location /education/7/abc-science {
# Unique handler for the URL you want to redirect.
# new url
return 301 $scheme://www.test.com/education/7/abc-science;
}
}还是需要在location块中添加$request_uri?
我是否需要使用这种方式将原来的URL重定向到新的URL?
location = /content/unique-page-name {
return 301 /new-name/unique-page-name;
}有人能帮我吗?这里怎么了?
任何帮助都是非常感谢的!谢谢!
发布于 2022-10-19 20:23:05
nginx文档声明server_name是虚拟主机的虚拟服务器名(域名)。
文档还解释了在那里允许什么样的输入。
您正在尝试添加URL而不是域,这就是配置无效的原因。
您需要为URL的URI部分添加一个location块。
https://serverfault.com/questions/1113517
复制相似问题