简体   繁体   English

Nginx 根据 url 中包含的内容进行重定向

[英]Nginx Redirect based on what is contained in the url

I am a noob when it comes to redirect and rewrites and such... My goal is to do a redirect based on what is sent to the server.在重定向和重写等方面,我是个菜鸟……我的目标是根据发送到服务器的内容进行重定向。 Example of the urls that will be sent:将发送的 URL 示例:

https://example.org/git/#123 https://example.org/git/#123

https://example.org/git/!123 https://example.org/git/!123

and redirect to url based if !并重定向到 url 如果! or # is part of it if !或 # 是其中的一部分,如果 ! then it would go to https://git.example2.com/userhere/repohere/merge_requests/123 if # then it would go to https://git.example2.com/userhere/repohere/issues/123 then it would go to https://git.example2.com/userhere/repohere/merge_requests/123 if # then it would go to https://git.example2.com/userhere/repohere/issues/123

Some help with a nginx location block would be nice. nginx 位置块的一些帮助会很好。

You can't match #123.你无法匹配#123。 So you need to use different character ie &所以你需要使用不同的字符,即 &

Use below sample rule.使用以下示例规则。

if ($request_uri ~ "^(.*)/!123)"{
return 301 https://git.example2.com/userhere/repohere/merge_requests/123;
}
if ($request_uri ~ "^(.*)/!456)"{
return 301 https://git.example2.com/userhere/repohere/merge_requests/456;
}

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

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