• Removing Slashes from a URL in NGINX

    Sometimes you need to remove multiple slashes from an address, for example:

    http://mysite.com//page//1.htm/ -> http://mysite.com/page/1.htm

    In this case, you can use the following construction to remove slashes from the middle:

    set $test_uri $scheme://$host$request_uri;
    if ($test_uri != $scheme://$host$uri$is_args$args) {
        rewrite ^ $scheme://$host$uri$is_args$args? permanent;
    }

    And from the end:

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