Discover Centmin Mod today
Register Now

Wordpress Nginx, WordPress, and Trailing Slash 301 Redirects

Discussion in 'Blogs & CMS usage' started by deltahf, Mar 4, 2018.

  1. deltahf

    deltahf Premium Member Premium Member

    Jun 8, 2014
    Local Time:
    2:55 AM
    I've recently noted that Nginx is returning the same WordPress pages for multiple URLs, with and without the trailing slash. For example:


    ...will both return the same page, but they won't redirect to one form or the other. Even though using rel="canonical" can mitigate this issue, it can be an SEO concern and can cause mis-reporting in Google Analytics, because the address to the same page can have different URLs.

    Please correct me if I'm wrong, but I believe the Centminmod Nginx configuration, by default, will provide a 301 redirect to form of the URL with the trailing slash. So...

    => 301 redirect to... =>

    That is how it works with actual directories, but if WordPress is handling the URL re-writes, it's not working as expected. I thought I had solved the issue with the following rule in my site's vhost.conf:

    location ~ /^([^.\?]*[^/])$ {
            try_files       $uri @addslash;
    location @addslash {
            return 301 $uri/;
    This was tested and working for me, but it stopped and I don't know exactly when or why.

    Is there another way I should be doing this? Perhaps this is something that Centminmod's WordPress Nginx re-write rules can address in the future?
  2. eva2000

    eva2000 Administrator Staff Member

    May 24, 2014
    Brisbane, Australia
    Local Time:
    4:55 PM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    you shouldn't need any rule nginx defaults to redirecting to slash version of directory by default - what happens if you disable that custom redirect rule altogether ?

    i.e. on my wordpress7 blog

    Code (Text):

    Code (Text):

    Code (Text):

    Code (Text):