Support » Plugin: W3 Total Cache » url trailing slash problem

  • Resolved Admiral

    (@behroooz)


    hello

    i have url trailing slash problem with Page Cache Disk Enhanced

    my url include trailing slash at the end http://domian.com/url/

    almost every thing is fine but in Disk Enhanced mode non trailing slash doesn’t redirect.

    http://domian.com/url –> http://domian.com/url/ not working

    i know if i use Disk Basic mod it will be fix! but i want to use Disk Enhanced mode and getting fix this problem.

    any one can help?

    tnx

    • This topic was modified 2 years, 3 months ago by Admiral.
    • This topic was modified 2 years, 3 months ago by Admiral.
    • This topic was modified 2 years, 3 months ago by Admiral.
    • This topic was modified 2 years, 3 months ago by Admiral.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @behroooz,

    We redirect URLs without trailing slash using PHP because we don’t know if the URL you’re visiting should be redirected or not (we could break some rewrite rules if we did). You could add your own rewrite rules to force a trailing slash. We can provide them if you need them, but we need to know which engine you’re using (Apache or Nginx).

    Thread Starter Admiral

    (@behroooz)

    apache+nginx

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello,

    This should be added to the server block in your Nginx config. You should be careful, there are exclusions in those rules so the REST API URL and files won’t get a trailing slash, but there might be more URLs that break when you add a trailing slash.

    # 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
    Thread Starter Admiral

    (@behroooz)

    i will try
    thank you

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