Reputation: 794
I'm trying to add redirects in nginx config file where if a user lands on any URL except a specific one, it will add a trailing slash after it. Also, it shouldn't add a trailing slash if there's a .
in it.
Example:
.
in the url)I did see this already which covers most of what I need:
#add trailing slash to all URLs except if it contains a .
rewrite ^([^.])*[^/]$ $1/ permanent;
I also figured out how to not add a trailing slash to a specific URL by doing something like this:
rewrite ^(?!no-trailing-slash).*[^/]$ $1/ permanent;
But I can't figure out how to combine them so that:
/
.
in the URLUpvotes: 2
Views: 1870
Reputation: 794
I actually figured it out with the help of HFZ's regex example. I used this and it works perfect:
^((?!no-trailing-slash)([^.]*[^\/]))$
and replace any match with:
$1/
Upvotes: 1