0

I'm still pretty new to nginx and I came up with this example that works to redirect "domain.com/gis" and "domain.com/gis/" to "domain.com/gis_public". The problem I have is it will not redirect "domain.com/GIS" or "domain.com/Gis".

I like to plan for all scenarios just in case someone types the GIS acronym in it's proper uppercase format or only capitalizes a single character. So I need to make this case-insensitive and I have failed to find a way. Any help will be appreciated.

location ~* ^/gis(?:/(.*))?$ {
  rewrite /gis(.*) https://domain.com/gis_public$1 permanent;
}

Edit My final code that works:

location ~* ^/gis(?:/(.*))?$ {
  rewrite (?i)^/gis(.*) https://domain.com/gis_public$1 permanent;
}

Thanks everyone for your help!

Gadjex
  • 3
  • 3
  • ~* should be a case insensitive match. Are you sure you've restarted nginx and you don't have something else in your configuration. http://nginx.org/en/docs/http/ngx_http_rewrite_module.html matching of a variable against a regular expression using the “~” (for case-sensitive matching) and “~*” (for case-insensitive matching) operators. – Drew Khoury Sep 24 '13 at 20:31
  • I do restart the server before each test. ~* does work for case-insensitive location matching. I couldn't get ~* to work on the rewrite. The marked answer below does work, however it isn't a "clean" solution. – Gadjex Sep 24 '13 at 20:53
  • maybe it doesn't apply to regex, check this out if you're interested in something a little cleaner http://serverfault.com/questions/498855/nginx-case-insensitive-rewrite – Drew Khoury Sep 25 '13 at 10:53
  • Thank you Drew. Adding (?i) to my rewrite is a cleaner solution. I edited my question to reflect my final code. – Gadjex Sep 25 '13 at 15:22

1 Answers1

0

It's just a regex, so you could match on that basis.

rewrite /[Gg][Ii][Ss](.*) https://....

There's probably a cleaner way to do this, but it doesn't come to mind right now.

Michael Hampton
  • 244,070
  • 43
  • 506
  • 972