Welcome! Log In Create A New Profile

Advanced

Redirect loop fixed, I need a better rule format

December 23, 2013 01:13AM
Hello everyone,

I have a little problem on hand, related to redirect loop for a specific location:
server {
listen 192.168.1.2:443 spdy ssl default_server;
...
location ^~ /alpha {
return 301 https://www.domain.com$request_uri;
}
...
}
I would like to redirect URL's of this format:
https://www.domain.com/alpha/delta/[more of $request_uri]
To:
https://www.domain.com/delta/[more of $request_uri]

I can access fine the https://www.domain.com/delta/... directory. When the GET is performed on https://www.domain.com/alpha/, it tries to use the old REQUEST URI which is obviously wrong. I solved the issue this way:
location ^~ /alpha {
location /alpha {
return 301 https://www.domain.com/;
}
location ~ ^/alpha/(.+)$ {
return 301 https://www.domain.com/$1;
}
}

Is there a better (more compact) way to achieve the same results?
With the rules listed above, I tell Nginx to redirect /alpha or /alpha/ to /.
If the $request_uri contains something after /alpha, I grab the part of $request_uri after /alpha and push it to /.

Thank you for helping me make this configuration part better.
SubjectAuthorPosted

Redirect loop fixed, I need a better rule format

TECKDecember 23, 2013 01:13AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 89
Record Number of Users: 1 on November 25, 2014
Record Number of Guests: 117 on November 25, 2014
Powered by nginx    Powered by FreeBSD    PHP Powered    Powered by Percona     ipv6 ready