
現時点では、これが私にとってはうまくいっています:
if ($request_uri = "/web/news.php?id=69") {
rewrite ^ https://www.camper-center.ch/? last;
}
/web/listing.php?monat=02&jahr=2020
しかし、今では、上記のような 1 つのパラメータではなく、 2 つのパラメータを持つ URL もあります。
if ($request_uri = "/web/listing.php?monat=02&jahr=2020") {
rewrite ^ https://www.camper-center.ch/news/aktuell.html?month=02&year=2020? last;
}
これは機能しないようです。何か提案はありますか?
ドイツ語のパラメータを含むサイトにリダイレクトされたので、リダイレクトしたところ、最終的には次のように機能しました。
if ($request_uri = "/news/aktuell.html?monat=02&jahr=2020") {
rewrite ^ https://www.camper-center.ch/news/aktuell.html?month=02&year=2020? last;
}
答え1
試す:
if ($args ~* "/web/listing.php?monat=02&jahr=2020") {
rewrite ^ https://www.camper-center.ch/news/aktuell.html?month=$arg_monat&year=$arg_jahr? last;
}
https://nginx.org/en/docs/http/ngx_http_core_module.html#変数
ニーズに合わせて調整するだけです。
答え2
次のアプローチを試すことができます。レベルmap
に を追加しますhttp
。
map $arg_id $idmap {
default 0;
"69" 1;
}
map $arg_monat $monatmap {
default 0;
"02" 1;
}
map $arg_jahr $jahrmap {
default 0;
"2020" 1;
次に、次のif
ブロックを使用します。
if ($idmap = 1) {
rewrite ^ https://www.camper-center.ch/? last;
}
if ($jahrmap$monatmap = "11") {
rewrite ^ https://www.camper-center.ch/news/aktuell.html?month=02&year=2020 last;
}
map
入力変数の内容を出力変数にマッピングします。URIから$arg_id
クエリ引数を取得します。上記では、nginx は引数をと比較します。一致する場合は値 1 を取得します。それ以外の場合は値 0 を取得します。id
map
id
69
$idmap
引数monat
と はjahr
同様に処理されます。それらの出力変数はif
比較で連結され、両方の引数が で指定された値と一致する場合はmap
がrewrite
実行されます。