nginx-用尾部斜线重写URL

我有一套专门的重写规则来适应多站点的cms设置。 我试图让nginx强制请求URL上的斜线。 我希望它redirect请求

domain.com/some-random-article to domain.com/some-random-article/

我知道有这个语义上的考虑,但我想做SEO的目的。

这是我目前的服务器configuration。

server { listen 80; server_name domain.com mirror.domain.com; root /rails_apps/master/public; passenger_enabled on; # Redirect from www to non-www if ($host = 'domain.com' ) { rewrite ^/(.*)$ http://www.domain.com/$1 permanent; } location /assets/ { expires 1y; rewrite ^/assets/(.*)$ /assets/$http_host/$1 break; } # / -> index.html if (-f $document_root/cache/$host$uri/index.html) { rewrite (.*) /cache/$host$1/index.html break; } # /about -> /about.html if (-f $document_root/cache/$host$uri.html) { rewrite (.*) /cache/$host$1.html break; } # other files if (-f $document_root/cache/$host$uri) { rewrite (.*) /cache/$host$1 break; } } 

我将如何修改这个添加尾部斜线? 我会假设必须检查斜线,以便您不会以domain.com/some-random-article结束

 rewrite ^(.*[^/])$ $1/ permanent; # Capture everything not with a trailing slash and add a trailing slash to it.