Home > Mobile >  Nginx redirect to another page if url contain specific query string
Nginx redirect to another page if url contain specific query string

Time:06-30

I want to redirect all URLs to another page if the URL contains a query string starting with fl=&fl=

incoming URL's can be anything starting with the query sting fl=&fl=

https://example.com/a-core/?fl=&fl=test&fl=test1&fl=xyz;&fl=test3&fl=test4&fl=test5

https://example.com/a-core/?fl=&fl=test&fl=test0&fl=cpl;&fl=test8&fl=test9&fl=test7

all of the above URLs are starting with query string fl=&fl= and need to be redirected to example2.com/test123

I have tried this but didn't work

if ($args = "fl=&fl=*") {
  return 301 https://example2.com/test123;
}

CodePudding user response:

The = operator does not understand wildcards such as *. You will need to use regular expression syntax.

For example:

if ($args ~* "^fl=&fl=") { ... }

See this document for details.

  • Related