{"id":154,"date":"2020-10-09T10:12:54","date_gmt":"2020-10-09T10:12:54","guid":{"rendered":"https:\/\/www.zebadger.com\/wp\/?p=154"},"modified":"2021-04-29T16:22:39","modified_gmt":"2021-04-29T16:22:39","slug":"nginx-case-insensitive-url","status":"publish","type":"post","link":"https:\/\/www.zebadger.com\/wp\/?p=154","title":{"rendered":"nginx case insensitive URL"},"content":{"rendered":"<p>There was a requirement for a website on the server to have a case-insensitive.<\/p>\n<p>There is no simple option in nginx to make it case-insensitive, there are also no nested if statements available.<\/p>\n<p>This isn&#8217;t easy to achieve, but the below seems to have done it me (for only 1 URI!)<\/p>\n<pre>location ~* ^\/TNG\/$ {\r\nreturn 301 https:\/\/www.theirdomain.co.uk\/TNG\/index.php;\r\n}\r\n\r\nlocation ~* ^\/TNG$ {\r\nreturn 301 https:\/\/www.theirdomain.co.uk\/TNG\/index.php;\r\n}\r\n\r\nset $BOTH \"\";\r\n\r\n# Does the case-insensitive pattern match?\r\nif ( $request_uri ~* ^\/TNG\/index.php$ )\r\n{\r\nset $BOTH \"${BOTH}1\";\r\n}\r\n\r\n# Is it not an exact match to the correct case?\r\nif ( $request_uri != \/TNG\/index.php )\r\n{\r\nset $BOTH \"${BOTH}2\";\r\n}\r\n\r\n# If both true, then redirect to the correct case\r\nif ( $BOTH = 12 )\r\n{\r\nreturn 301 https:\/\/www.theirdomain.co.uk\/TNG\/index.php;\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>There was a requirement for a website on the server to have a case-insensitive. There is no simple option in nginx to make it case-insensitive, there are also no nested if statements available. This isn&#8217;t easy to achieve, but the below seems to have done it me (for only 1 URI!) location ~* ^\/TNG\/$ { [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-154","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.zebadger.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/154","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zebadger.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zebadger.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zebadger.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zebadger.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=154"}],"version-history":[{"count":2,"href":"https:\/\/www.zebadger.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/154\/revisions"}],"predecessor-version":[{"id":192,"href":"https:\/\/www.zebadger.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/154\/revisions\/192"}],"wp:attachment":[{"href":"https:\/\/www.zebadger.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zebadger.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=154"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zebadger.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}