Nginx使用通配符wordpress重定向字符串变量

时间:2017-01-31 09:48:22

标签: redirect nginx

我在Google搜索控制台中发现了一堆奇怪的404错误,并且我的网站中没有网址,我需要将其重定向到我的主页。

http://www.example.com/plugins/feedback.php?href=http%3A%2F%2Fwww.example.com%2Fremain-url-1%2F&_fb_noscript=1
http://www.example.com/plugins/feedback.php?href=http%3A%2F%2Fwww.example.com%2Fremain-url-2%2F&_fb_noscript=1
http://www.example.com/plugins/feedback.php?href=http%3A%2F%2Fwww.example.com%2Fremain-url-3%2F&_fb_noscript=1

我已经做了两次尝试,但它没有工作

rewrite ^/plugins/feedback(/.*)$ http://www.example.com/ permanent;
rewrite ^/plugins/feedback.php?href=http://www.example.com(/.*)$ /blog/ permanent;

是否可以使用一张外卡重定向?

1 个答案:

答案 0 :(得分:1)

rewrite指令不能用于过滤参数,因为它使用的规范化 URI不包含查询字符串。您可以使用$args变量访问参数,也可以使用$arg_xxx变量单独访问参数。

但是,$request_uri包含整个URI(包括查询字符串),可以与if块或map一起使用,以测试您所寻找的参数是否存在。< / p>

例如:

if ($request_uri ~ ^/some/regular/expression) {
    return 301 /;
}

该块可以放在server块范围内,也可以放在通常处理/plugins/feedback.php URI的位置块内。

有关详细信息,请参阅以下文档:if directivemap directiveif usage restrictions