Regex rule in an NGinx Config to only compare against the first url param -


here example of our current nginx rule redirect traffic 1 base domain (result of dns migration):

location ~* /(var1|var2|var3) {     rewrite ^ http://newurl.com$uri? permanent; } 

so using url above following url: oldurl.com/var1/foo
redirected to: newurl.com/var1/foo

using approach oldurl.com/foo not redirect new domain designed , want.

however problem having if keywords found in location statement used anywhere in url get's redirected. want pattern match against variables found in first /###/ folder of url sequence.

in other words want oldurl.com/var1/foo
redirect not oldurl.com/foo/var1

given our current regex rule finds var1 in url (even though in 2nd position) , redirects.
in other words: oldurl.com/foo/var1
redirects newurl.com/foo/var1
don't want to.

my regex not spiffy pattern match against first block of /###/ code. can me proper regex/nginx statement?

it's regular expression need anchor beginning of url path ^ this:

location ~* ^/(var1|var2|var3) {     rewrite ^ http://newurl.com$uri? permanent; } 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -