小编Sky*_*n42的帖子

NGINX删除.html扩展名

所以,我找到了在我的页面上删除.html扩展名的答案,该代码可以正常工作:

server {
    listen 80;
    server_name _;
    root /var/www/html/;
    index index.html;

    if (!-f "${request_filename}index.html") {
        rewrite ^/(.*)/$ /$1 permanent;
    }

    if ($request_uri ~* "/index.html") {
        rewrite (?i)^(.*)index\.html$ $1 permanent;
    }   

    if ($request_uri ~* ".html") {
        rewrite (?i)^(.*)/(.*)\.html $1/$2 permanent;
    }

    location / {
        try_files $uri.html $uri $uri/ /index.html;
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,如果我打开mypage.com,它会将我重定向到mypage.com/index
这不会通过将index.html声明为索引来解决吗?任何帮助表示赞赏.

html nginx

10
推荐指数
1
解决办法
1万
查看次数

标签 统计

html ×1

nginx ×1