I'm looking to write a simple rewrite rule where I basically am trying to say the following
If the requested URI is text/index.html (or test/) and the GeoIP Organization equals "My GeoIP Value" then server test/index2.html
I've tried a few directives and nothing is really working as I would expect.
The current setup I have is
map $geoip_org $redirectMe {
default 0;
'My GeoIP Org Value' 1;
}
server{
....
location /test {
try_files $uri index.html;
expires -1;
if ( $redirectMe ) {
rewrite ^/test/index.html$ /test/test2.html break;
}
}
....
}
I find that it either redirects nothing or redirects all of the time regardless of my IP Organisation, so as if it's caching the redirect which I thought the expires -1 would sort out.
I'm also notice I receive the HTTP 304 for requests regardless of whether they are redirected or not.
Does anyone have any pointers? I thought it would be a simple thing. I've also tried not using the map and putting the comparison inside the location but this did not work and using the map outside of the server would allow me to change the logic easier later.
Update The answer is that it was actually working and that is was just the cache not refreshing when I ran a service nginx reload.
The solution was to use service nginx force-reload (or restart though that is overkill) and it would wor