M
M
Master_li2015-03-13 14:45:16
Nginx
Master_li, 2015-03-13 14:45:16

How to redirect nginx to another site by specifying user agent?

Tell me how to register correctly in the nginx config
so that when accessing the url domen1/?reklama=1 from all user agents except bots, a 302 redirect to https://domen2/lang/home?reklama=1
is performed in the config there is such a
location ~ /?reklama= 1{
if ($http_user_agent ~ firefox) {
return 302 https://domen2/lang/home?reklama=1;
}
but it doesn't work if I remove the question mark it works, tell me how to correctly write the regular expression

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Korvyakov, 2015-03-13
@LNShadow

map "$http_user_agent:$args" $redirect {
"~(Bot1|Bot2):reklama=1" "0";
default "1";
}
if ($redirect) {
return 302 https://domen2/lang/home?reklama=1;
}
something like this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question