
그래서 현재 이것은 나를 위해 일하고 있습니다.
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을 가져옵니다. 그렇지 않으면 값 0을 가져옵니다.
인수 monat
와 jahr
유사하게 처리됩니다. 해당 출력 변수는 if
비교를 위해 연결되며, 두 인수가 모두 에 지정된 값과 일치하면 map
가 rewrite
수행됩니다.