微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如果查询参数存在于nginx上,则重定向

我正在使用IPB论坛.我设法使用友好的网址与Nginx服务器配置修改.但是,我需要将旧论坛的URL重定向重定向PHP文件,以获取主题(或论坛,成员等)的当前URL.例如:如果url类似于/forum/index.PHP?board=23,我将重定向到redirector.PHP.

这是我目前的配置,能够在IPB上使用友好的URL

    location /forum {
        try_files $uri $uri/ /forum/index.PHP;
        rewrite ^ /forum/index.PHP? last;
    }

当我在这个位置块中插入if语句时,如下所示,我无法检索查询参数“board”.

location /forum {
        if ($arg_board != "") {
            rewrite ^ /redirector.PHP?q=$arg_board break;
        }
        try_files $uri $uri/ /forum/index.PHP;
        rewrite ^ /forum/index.PHP? last;
    }

这里缺少什么?

解决方法:

你的问题与使用break而不是last.从文档:

http://wiki.nginx.org/HttpRewriteModule#rewrite

last – completes processing of current rewrite directives and restarts the process (including rewriting) with a search for a match on the URI from all available locations.

break – completes processing of current rewrite directives and non-rewrite processing continues within the current location block only.

由于您没有在/ forum位置块中为/ redirector定义处理程序,因此if(..){rewrite}不会执行您想要的操作.将该断点设为最后一个,以便重写可以触发相应的位置块.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐