1

I'm using Nginx and in my .conf file I have added a rewrite to remove all trailing slashes on the urls

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

This works perfectly except for the /blog folder which enters into an infinite loop.

As I understand it it is because the /blog folder is a directory and all directories automatically add a trailing slash e.g. /blog/

Is there a way I can disable the trailing slash on directories in Nginx?

Many thanks!

  • Why would you want to do that. A directory always has a trailing slash in urls... – EJTH Apr 30 '15 at 19:21
  • Because my URL structure is without trailing slashes and it needs to be consistent for SEO. I have a Magento site running in the root and a wordpress site in the /blog folder. I want the blog to appear as if it's just another page instead of a directory. It doesn't make sense that all pages on the magento site and the wordpress site are without trailing slashes except for the /blog/ page. – user3429664 May 01 '15 at 08:56

1 Answers1

3

Change your rewrite rule to not match blog:

rewrite ^/((?!blog).+)/$ /$1 permanent;
Ben
  • 341
  • 4
  • 16