从nginx中的特定URL中删除尾部的斜杠

我最近把我的博客从使用WordPress转移到使用Jekyll(我喜欢我的博客的静态文件的想法)。 我正在使用Nginx(之前使用它与PHP-FPM),并有东西安装来处理的东西。 我遇到了一个问题,我不知道如何解决。

我正在使用的URL结构是

/atthekeyboard/YYYY/MM/DD/title-of-post 

我有大约5年的博客文章已经被谷歌索引,他们是

 /attheykeyboard/YYYY/MM/DD/title-of-post/ 

我想用尾部斜杠重写所有的旧调用,直到Google索引所有新的东西,才能使用非尾部的斜杠URL。

这里是我已经nginxconfiguration的东西:

  location /atthekeyboard { index index.html; try_files $uri.html $uri/ /notfound.html; } 

我正在使用try_files,因为这些post实际上是以title-of-post.html的forms保存的,我不想要.html部分。

预先感谢您的build议和解决scheme!

像这样的东西应该删除尾部的斜杠,然后让Nginx重新分配位置块。

 location ~ ^(/atthekeyboard/.+)/$ { set $noslash $1; rewrite ^ $noslash permanent; } 

我认为HTTPRewriteModule是你正在寻找的