I've got a few double slashes I can't get my nginx.conf file to rewrite as single slashes. I'm able to get it to rewrite a majority of double slashes, for example I can get http://domain.com/feature//feature-name/ to http://domain.com/feature/feature-name/
if ($request_uri ~ "^[^?]*//") {
rewrite "(.*)" $scheme://$host$1 permanent;
}
The issue I'm having is that if I have a double slash immediately following the .com, it won't rewrite to a single slash. My two examples that I'm having trouble with are http://domain.com// and http://domain.com//features/
I've tried using the merge_slashes directive, and a variety of other rewrites. I'm just at a loss as to why they all seem to work EXCEPT right after the .com. Thanks!
The real question is : how did you end up with such URLs ?
If you use nginx normally you will not get such a behaviour as nginx is normalizing URIs (i.e. it will compress several adjacent slashes in one, decode URLs and resolve relative paths).
The normalization result of the URI from the current request being processed is stored in $uri
variable.
So the following part should never be necessary.
if ($request_uri ~ "//") {
return 301 $uri;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With