How I can write a condition in the nginx config testing if a q
parameter was entered in the URL?
This doesn't work:
if ($arg_q) {
return 301 "/someurl";
}
It catches URLs like
/search?entered_search=1&q=123
But it doesn't catch URLs like
/search?entered_search=1&q=
Something like this might work. It says "if the query string contains the sequence 'q=' send a redirect". At least that's what I think it says, I'm not great with regex. I've tested it and it works, but there may be side effects depending what query strings you could get.
This answer helped me work it out.