如何在除扩展名之外的每个URL的末尾添加斜杠?

时间:2014-09-24 15:04:25

标签: nginx rewrite php

需要帮助。

如何在除扩展名之外的每个网址的末尾添加斜杠?

我绑定使用

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

它正在运行,但在每个网址的末尾添加斜杠,包括css,js,images ......

1 个答案:

答案 0 :(得分:1)

我认为这对你有用。遗憾的是,我们在Nginx中没有NOT的语法,所以我们必须进行空匹配,然后使用/来匹配任何其他内容。

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

更多信息here