我试图掩盖一个附属链接,所以我想要一个302重定向通过nginx
我希望将所有/go
链接重定向到相应的附属链接,因此所有链接重定向都像mydomain.com/go/affiliate
重定向到> https://www.affiliatelink.com
现在这就是我所拥有的
location /go {
rewrite ^/affiliate$ https://www.affiliatelink.com redirect;
}
我什么都试过了,但我似乎无法使它发挥作用。有我需要做的特定文件吗?
我已经试过/sites-enabled/default
和/conf.d/nginx.conf
了
发布于 2021-02-22 04:14:34
您的重写不起作用,因为您请求的URL路径是/go/affiliate
,但是rewrite
匹配精确的路径/affiliate
,这在location /go
中是永远找不到的。修复这个问题很简单,但出于性能原因,您应该尽可能避免regex。
不要使用这种rewrite
,而是使用两种替代方法中的一种:
location
:location /go/代销商{返回302 https://affiliate.example.com/;}map
代替。映射$uri $aff_redirect { default“;"/go/affiliate”"https://affiliate.example.com/“;# more链接}A map
进入任何server
块之外的http
块。要使用它,请检查适当的server
块中的$aff_redirect
变量。如果($aff_redirect) {返回302 $aff_redirect;}https://serverfault.com/questions/1054552
复制相似问题