nginx重写utf-8 endcoded url

时间:2012-06-24 12:47:11

标签: url-rewriting nginx rewrite

我正在使用Nginx,我想用以下两个参数重写所有网址:

title=%E7%89%B9%E6%AE%8A

from=(any datatime)

到主页。

我不知道如何写规则,有人会帮助我吗?

编辑:

我想重写网址:

http://example.com/index.php?days=30&from=20120122083408&limit=250&title=%E7%89%B9%E6%AE%8A

http://example.com/index.php?from=20120622063000&limit=20&title=%E7%89%B9%E6%AE%8A

http://example.com/index.php?from=20030422063000&title=%E7%89%B9%E6%AE%8A

http://example.com

1 个答案:

答案 0 :(得分:2)

Nginx不支持逻辑AND操作,但我们可以使用“小黑客”: 这应该可以帮到你:

location = /index.php {
    set $redirect "";

    # if we have get parameter "title":
    if ( $arg_title ) {
        set $redirect "Y";
    }

    # if we have get paramter "from":
    if ( $arg_from ) {
        set $redirect "${redirect}ES";
    }

    # Now in the variable $redirect should be a word "YES":
    if ( $redirect = YES ) {
        rewrite ^ / last;
    }

    ....
}

P.S。您还可以使用302重定向,直接将用户移至 /