P
P
part_os2020-02-20 19:15:15
Nginx
part_os, 2020-02-20 19:15:15

How to remove slash only on files in nginx?

Hello everyone, please tell me, I'm trying to set up so that there would be no slash on all files
like https://photo-gileva-olga.ru/sitemap.xml/
but what would remain on https://photo-gileva-olga.ru/packages /

Tell me how to configure nginx to have this behavior?
site.ru/index.php - open if this is a file
site.ru/inex/ - closed if this is a directory

server {
    listen 80;

    server_name photo-gileva-olga.ru;

    if ($request_uri ~ "^(.*)index\.(?:php|html)/(.*)") {
         return 301 $1$2;
    }
    if (!-f $request_filename) {
        rewrite [^/]$ $uri/ permanent;
    }

    if ($request_uri ~ ^(?P<left>[^?]*?)//+(?P<right>[^?]*)) {
        rewrite ^ $left/$right permanent;
    }

    index index.php;

    location / {
       try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_pass php:9000;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        internal;
    }

    location ~ \.php$ {
        return 404;
    }

}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question