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 Setup Uwsgi with NGINX for Python
How to Use NGINX try_files
NGINX Pass Headers from Proxy Server
How to Serve Static Files in NodeJS using NGINX
How to Force NGINX to Serve New Static Filles
How to Change NGINX Config Without Restarting
NGINX Alias vs Root
Difference between $host and $http_host in NGINX

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