简体   繁体   中英

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

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...

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM