0

Need help.

How to add slash to the end of every url except extensions?

I tied to use

rewrite ^(.*[^/])$ $1/ permanent;

It is working but adding slash to the end of every URL including css, js, images...

1 Answers1

1

I think this will work for you. Sadly we do not have a syntax for NOT in Nginx, so we have to make an empty match and then use / to match anything else.

location ~* ^.+\.(?:css|cur|js|jpg|jpeg|gif|htc|ico|png|html|xml)$ {
    # empty
}
location / {
    rewrite ^(.*[^/])$ $1/ permanent;
}

More info here.

Community
  • 1
  • 1
balintant
  • 2,774
  • 1
  • 19
  • 33