NGINX allows you to rewrite requested URLs in numerous ways. In most cases it does a case sensitive rewrite of URLs. But sometimes you may need to do case insensitive rewrite in NGINX. In this article, we will learn how to do this.
How to do Case Insensitive Rewrite in NGINX
Let us say you want to rewrite URL http://example.com/product to http://example.com/new-product. Typically, here is the rewrite statement we use in our NGINX server configuration to implement the above redirect.
rewrite "product" http://www.example.com/new-product redirect; OR location /foobar { rewrite "product" http://www.example.com/new-product redirect; }
The above configuration will redirect URLs starting with /product but not those with /PRODUCT or any different case of /product.
In case you want to do a case insensitive match of URLs, you can just add (?i) before capture group as shown below.
rewrite "(?i)product" http://www.example.com/new-product redirect; OR location /foobar { rewrite "(?i)product" http://www.example.com/new-product redirect; }
The above configuration should help you match your required capture group irrespective of the case of URL.
In this article, we have learnt how to do case sensitive rewrite in NGINX.
Also read:
How to Forward Request to Another Port in NGINX
How to Check if Key Exists in Python Dictionary
How to Get Random Number Between Two Numbers in JS
NGINX Catch All Location
How to Download Images in Python
Related posts:
How to Exclude Requests from NGINX Log
How to Enable HTTP Strict Transport Policy (HSTS) in NGINX
How to Fix NGINX Bind to 0.0.0.0:80 Failed Error
Set NGINX to Catch All Unhandled Virtual Hosts
Cannot Access NGINX From Outside
How to Change NGINX Config Without Restarting
How to Modify Response Header in NGINX
How to Force NGINX to Serve New Static Filles

Sreeram has more than 10 years of experience in web development, Python, Linux, SQL and database programming.