'NginX: rewrite backslashes to Forward-slashes

I want to write NginX rewrite rule to convert all Backslashes to forward-slashes.

Something exactly like: Using .htaccess to replace backslash in URL with forward-slash

however, I am working in NginX while above link refers to Apache.

I migrated my application from Windows IIS to Linux Tomcat and hence I need to get this done. My URL has multiple Backslashes which gets resolved fine in IE and Chrome but Firefox is resolving them to its Unicode %5C and hence I need to rewrite.

My sample URL in WIndows/IIS: https://doman.com/company/.\images\company\companylogo.png

When I moved stuff to Linux/Tomcat, above URL works in Chrome and IE, but Firefox is converting above backslashes to %5C. So Firefox is trying to resolve: https://doman.com/company/.%5Cimages%5Ccompany%5Ccompanylogo.png

And needless to say, Firefox fails to load the image.

Here is what I tried so far in my nginX configuration (Once statement at a time)):

rewrite \ / permanent;
rewrite \\ \/ permanent;  # with escaping thinking it might help
rewrite (.*)\(.*)\(.*)\(.*)  $1/$2/$3/$4 permanent;
rewrite (.*)\(.*)\(.*)\(.*)  $1\/$2\/$3\/$4 permanent;

Howcer , none seem to work and last 2 statements are throwing NginX configuration Error.

Any pointers would be of great help. There are thousands such URLs and I cannot imagine of converting all of them into Forward-Slash'd style.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source