在没有 301 重定向的情况下访问文件夹中的 index.html

Access index.html in folder without 301 redirect

我有一些 index.html 文件放在文件夹中以获取一些不错的 url -

site.com/about

其中 index.html 位于关于文件夹中。但我看到我的网站。com/about 被 301 重定向到 site.com/about/ 我不确定 301 是从哪里生成的。它不在配置中。

/about/ 也有一个 301 结果。

我想这是有道理的,因为我正在重定向到 index.html 文件,但它不应该是重写吗?有没有办法 return 200 for /about 而不是 301 to about/?

我正在使用 nginx

服务器块:

server {
    listen IP;
    server_name site.com;
    rewrite / $scheme://www.$host$request_uri permanent;    

}

server {
    listen IP:80;
    server_name site.com *.site.com;
    root /var/www/vhosts/site.com/htdocs;
    charset utf-8;
    rewrite_log on;

    location / {
        index index.html index.php;
    try_files $uri $uri/ /$uri.php;
        expires 30d;
    }

    if ($request_uri = /index.php) {
        return 301 $scheme://$host;
    }   
    if ($request_uri = /index) {
        return 301 $scheme://$host;
    } 

    location  /. {
        return 404;
    }
    location ~ .php/ {
        rewrite ^(.*.php)/  last;
    }    
    include "ssl_offloading.inc";
    location ~ .php$ {
#        if (!-e $request_filename) { rewrite / /index.php last; }
        if (!-e $request_filename) { rewrite / /404.php last; }

    }
}

index 指令和 try_files 指令的 $uri/ 元素具有通过执行外部命令向目录名称添加尾随 / 的副作用重定向。

为了避免外部重定向和 return 一个适当的索引文件,当出现一个无斜杠的目录名时,在 try_files 指令中明确实现 index 功能:

location / {
    try_files $uri $uri/index.html $uri.php;
    expires 30d;
}

请注意,.php 仅适用于此位置的最后一个元素。如果您需要检查 $uri/index.php(除了 $uri.php),您可以使用命名位置块 - 并将您的 fastcgi 配置 移动或复制到其中。

例如(基于您的服务器块):

root /var/www/vhosts/site.com/htdocs;

error_page 404 /404.php;

location / {
    try_files $uri $uri/index.html @php;
    expires 30d;
}
location @php {
    try_files $uri.php $uri/index.php =404;

    include       fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    ...
    fastcgi_pass ...;
}

location = /index.php { return 301 $scheme://$host; }
location = /index { return 301 $scheme://$host; }
location /. { return 404; }

location ~* \.php(/|$) { rewrite ^(.*)\.php  last; }

include "ssl_offloading.inc";