1

Nginxを使用していますが、すべてのURLを次の2つのパラメーターで書き直したいと思います。

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

from=(any datatime)

ホームページへ。

ルールの書き方がわかりませんが、誰か助けてくれませんか?

編集:

次のようなURLを書き直したい:

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
4

1 に答える 1

2

Nginxは論理積演算をサポートしていませんが、「小さなハック」を使用できます。これは次のことに役立ちます。

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;
    }

    ....
}

PSまた、302リダイレクトを使用して、ユーザーを/に直接移動することもできます。

于 2012-06-26T11:32:28.193 に答える