redirect loop with try_files

mschipperheyn nginx-forum at nginx.us
Sat May 4 14:20:32 UTC 2013


Hi,

I have a front end nginx webserver with behind it a tomcat server. I ran
into a nasty little redirect loop issue that I still don't understand. I'm
trying to redirect users who have a session cookie to a different page than
the other users

I have a configuration such as this:

## Rewrite index requests
rewrite ^(.*)/index.(.*)$ $1/ permanent;

map $cookie_msa_country $ctry {
	default         0;
	NL              "nederland/NL_";
	BR              "brasil/BR_";
}

map $cookie_msa_lng $lng {
	default         "nl";
	nl              "nl";
	pt              "pt";
	es              "es";
	en              "en";
}
location = / {
	   set $red  0;
	   if ($http_cookie ~* "JSESSIONID"){
			   set $red 1;
	   }
	   if ($ctry = 0){
			   set $red 0;
	   }
	   if ($red = 1){
			   rewrite ^(.*)$ http://$host/$ctry$lng/account/wall/;
	   }

	   try_files /notthere.html @proxy;
}


When a users types in domain www.site.com, he ends up in an endless loop. I
tried various things but without luck. Any suggestions how to avoid this?

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,238837,238837#msg-238837



More information about the nginx mailing list