
Por el momento esto me funciona:
if ($request_uri = "/web/news.php?id=69") {
rewrite ^ https://www.camper-center.ch/? last;
}
Pero ahora también tengo URL /web/listing.php?monat=02&jahr=2020
con dos parámetros en lugar de uno como el anterior.
if ($request_uri = "/web/listing.php?monat=02&jahr=2020") {
rewrite ^ https://www.camper-center.ch/news/aktuell.html?month=02&year=2020? last;
}
esto no parece funcionar. ¿Tienes alguna sugerencia?
Como me redirigió al sitio con parámetros alemanes, los redirigí y al final funcionó así:
if ($request_uri = "/news/aktuell.html?monat=02&jahr=2020") {
rewrite ^ https://www.camper-center.ch/news/aktuell.html?month=02&year=2020? last;
}
Respuesta1
Intentar:
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
Simplemente adáptate a tus necesidades.
Respuesta2
Podrías probar el siguiente enfoque. Añade un map
al http
nivel:
map $arg_id $idmap {
default 0;
"69" 1;
}
map $arg_monat $monatmap {
default 0;
"02" 1;
}
map $arg_jahr $jahrmap {
default 0;
"2020" 1;
Luego use los siguientes if
bloques:
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
asigna el contenido de la variable de entrada a la variable de salida. $arg_id
toma el argumento de consulta id
del URI. En lo map
anterior, nginx compara el id
argumento con 69
. Si coincide, $idmap
obtiene el valor 1. De lo contrario, obtiene el valor 0.
Los argumentos monat
y jahr
se manejan de manera similar. Sus variables de salida se concatenan en if
comparación y, si ambos argumentos coinciden con los valores especificados en map
, se rewrite
realiza.