Welcome! Log In Create A New Profile

Advanced

exact match on location with regular expression

Posted by mschipperheyn 
exact match on location with regular expression
February 06, 2012 01:27PM
Hi,

Our site has urls such as
/mexico/MX_en/
/mexico/MX_es/projects/
/brasil/BR_pt/account/

The home page is at "multiple" locations per country
/

and e.g.

/mexico/MX_en/

These pages show the same content.

For first time users who arrive at these page, we have an introductory page.
After you register, we don't want people to arrive at these pages anymore, so we write a cookie and let nginx redirect to a different page when the cookie is there. So far so good.

The problem is rewriting pages with the url
/mexico/MX_en/

Because these urls are not fixed, we want to match these with a regular expression such as below.
However, this also matches urls based on the same base including the redirect url itself

/mexico/MX_en/search/
/mexico/MX_en/account/

#this works fine
location = / {
if ($ctry !~ 0){
rewrite ^(.*)$ http://$host/$ctry$lng/search/;
}
try_files $uri @proxy;
}
#this does not
location ~ /[^/]+/.._../ {
if ($ctry !~ 0){
rewrite ^(.*)$ http://$host$uri/search/;
}

try_files $uri @proxy;
}

Can anybody point me the way to be able to have an exact match on a url that uses a regular expression?

Kind regards,
Marc
Re: exact match on location with regular expression
February 08, 2012 08:15AM
Anyone?
Re: exact match on location with regular expression
February 14, 2012 08:57AM
Anyone? I also tried using a "longer" regular expression to match but that didn't work either.

location = / {
try_files $uri @home;
}

location ~ ^/[^/]+/.._../(.*) {
try_files $uri @proxy;
}

location ~ ^/[^/]+/.._../ {
try_files $uri @home;
}

location @home {
if ($ctry !~ 0){
rewrite ^(.*)$ http://$host/$ctry$lng/search/;
}

try_files $uri @proxy;
}

location / {
keepalive_timeout 30;
rewrite ^([^.]*[^/])$ $1/ permanent;
try_files $uri @proxy;
}


$ctry and $lng are set based on cookie existence.
I always end up going to @proxy except on the site url which is matched by = /

Damned frustrating, this.
Re: exact match on location with regular expression
February 19, 2012 11:25AM
Thanks all. Really helpful
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 186
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready