• Resolved vsiljan

    (@vsiljan)


    Hello,

    I have a wordpress page setup on apache that uses disk enchaned. When I set my permalinks to trailing slashes duplicate pages are created. I found this solution in another thread (link to thread https://www.ads-software.com/support/topic/url-trailing-slash-problem/) that is for ngnix.

    # BEGIN Force trailing slash
    set $force_trailing_slash -1;
    if ($request_uri ~ "^/.+[^/]$") {
        set $force_trailing_slash 1;
    }
    if ($request_uri ~ "^/(wp-json|\.well-known)/") {
        set $force_trailing_slash -1;
    }
    if ($request_uri ~ "\.(xml|jpg|png|pdf|js|css)$") {
        set $force_trailing_slash -1;
    }
    if ($request_uri ~ "((\?|\&)[^=]+\=[^&]+)+$") {
        set $force_trailing_slash -1;
    }
    if (-f $request_filename) {
        set $force_trailing_slash -1;
    }
    if ($force_trailing_slash = 1) {
        return 301 https://$host$request_uri/;
    }
    # END Force trailing slash

    Since I’m not that familiar with apache can you please provide me with the equivilent solution for apache.

    Thank you in advance and I look forward to your response!

Viewing 1 replies (of 1 total)
  • Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @vsiljan

    Thank you for reaching out and I am happy to assist you with this.
    The reason this happens is that page-enhanced rules work with and without trailing slash. We don’t know if the user wants the trailing slash or not. Also adding a rewrite rule in the Nginx or Apache config, we can’t do that because we don’t know which URLs should be opposite. For example, the contact form 7 plugin was not working with trailing slash, but we don’t know if the user installed that plugin. Also, we don’t know what plugins work with what rules and we don’t want to have to add a million possibilities for each plugin there is. There are also wp-json requests, feeds, and all others that stop working with a slash.
    There is an option to force trailing slash in .htaccess, however if this does not work for you you should remove the rule.

    # Force trailing slash
    <IfModule mod_rewrite.c>
    	RewriteCond %{REQUEST_URI} /+[^\.]+$ 
    	RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
    </IfModule>

    Alternatively, you can use the Disk caching method or memory-based caching.

    I hope this helps!

    Thanks!

Viewing 1 replies (of 1 total)
  • The topic ‘url trailing slash problem for apache’ is closed to new replies.