
所以目前這對我有用:
if ($request_uri = "/web/news.php?id=69") {
rewrite ^ https://www.camper-center.ch/? last;
}
但現在我也有像是/web/listing.php?monat=02&jahr=2020
兩個參數的 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#variables
只需適應您的需求即可。
答案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
取得查詢參數。id
在map
上面,nginx 將參數id
與69
.如果匹配,則$idmap
取得值 1。
參數monat
和jahr
的處理方式類似。它們的輸出變數在比較中串聯起來if
,如果兩個參數都與 中指定的值匹配map
,則rewrite
執行 。