Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex Nginx位置块未按预期匹配?_Regex_Url_Redirect_Nginx - Fatal编程技术网

Regex Nginx位置块未按预期匹配?

Regex Nginx位置块未按预期匹配?,regex,url,redirect,nginx,Regex,Url,Redirect,Nginx,我们最近制作了一个新网站,它打破了旧网站上许多丑陋的URL。现在那些丑陋的URL得到了404响应。我们想修复其中一些链接,因为它们破坏了我们合作伙伴的一些网站,这些网站曾经链接到它们 在我的nginx配置中,我有: location = /index.cfm?pagepath=Grain_Marketing&id=15404 { return 301 $scheme://www.[redacted].com/grain-marketing/; } location /index

我们最近制作了一个新网站,它打破了旧网站上许多丑陋的URL。现在那些丑陋的URL得到了404响应。我们想修复其中一些链接,因为它们破坏了我们合作伙伴的一些网站,这些网站曾经链接到它们

在我的nginx配置中,我有:

location = /index.cfm?pagepath=Grain_Marketing&id=15404 {
    return 301 $scheme://www.[redacted].com/grain-marketing/;
}

location /index.cfm {
    return 301 $scheme://www.[redacted].com/;
}
第一个位置块似乎根本不起作用。第二个确实有效。我们希望第二个可以充当“一网打尽”的角色,如果第一个完全匹配,那么就应该使用第一个

我试过:

  • 位置~*
  • 位置
  • 位置=
…但似乎无法让它发挥作用

编辑: 我现在已经试过了,但仍然不起作用

location /index.cfm {
    rewrite index\.cfm\?/pagepath=Grain_Marketing $scheme://www.[redacted].com/grain-marketing/ permanent;
    return 301 $scheme://www.[redacted].com/;
}

没关系,我知道了。这是因为位置似乎看不到参数。这就是解决方案:

location /index.cfm {

    if ($args ~* pagepath=Grain_Marketing) {
        return 301 $scheme://www.[redacted].com/grain-marketing/;
    }

    return 301 $scheme://www.[redacted].com/;

}