简体   繁体   English

Nginx 重定向被忽略

[英]Nginx redirect being ignored

I'm trying to create a redirect for all URLs on a domain that contains /comfy/ to another domain, but keeping the rest of the request.我正在尝试为包含 /comfy/ 的域上的所有 URL 创建重定向到另一个域,但保留请求的 rest。

For example https://www.example.org/system/comfy/cms/files/files/000/002/012/profile/AdobeStock_194204879.jpeg例如https://www.example.org/system/comfy/cms/files/files/000/002/012/profile/AdobeStock_194204879.jpeg

to

https://www2.example.org/system/comfy/cms/files/files/000/002/012/profile/AdobeStock_194204879.jpeg https://www2.example.org/system/comfy/cms/files/files/000/002/012/profile/AdobeStock_194204879.jpeg

In nginx in the server block for example.org I have在 nginx 在 example.org 的服务器块中我有

location ~ ^/comfy/(.*) {
return 301 $scheme://www2.example.org/$request_uri;

} }

but i'm still getting a 404, with the original domain, ie it's still accessing但我仍然收到 404,原始域,即它仍在访问

https://www.example.org/system/comfy/cms/files/files/000/002/012/profile/AdobeStock_194204879.jpeg

I have also tried我也试过

rewrite ^(/comfy/)(.*)$ http://www2.example.org/$2 permanent;

and

rewrite ^/comfy/(.*) http://www2.example.org/$1 break;

but these are failing too.但这些也失败了。 What am I missing?我错过了什么?

Thanks!谢谢!

Ok, turns out I needed to do好的,事实证明我需要做

location ~ ^/system/comfy/cms/(.*) {
    return 301 $scheme://www2.example.org/$request_uri;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM