T
T
TechNOIR2020-06-18 11:24:24
Nginx
TechNOIR, 2020-06-18 11:24:24

nginx. How to make a redirect provided referer and user_agent?

Good afternoon. Please
tell me How to make a redirect provided referer and user_agent?
I currently have valid_referers

valid_referers sub.test.com;
if ($invalid_referer) {
   return 301 https://test.com;
}


Is it possible to make a condition that "if the referrer is invalid and the user_agent is not safari, then the redirect"?
It is necessary to exclude the safari if the referrer is invalid.

thanks in advance

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
ky0, 2020-06-18
@ky0

Can. It's just that the condition will be more spread out.

D
dodo512, 2020-06-18
@dodo512

map "$invalid_referer;$http_user_agent" $redirect {
    "~^;"            0;
    "~^1;.* Safari/" 0;
    "~^1;"           1;
}


valid_referers sub.test.com;
if ($redirect) {
   return 301 https://test.com;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question