使用NGINX的链接删除的.html

问题描述 投票:0回答:2

我已经为我的nginx的站点可用的文件此配置。它创建类似https://website.com/news-id.html链接

我想要做的是去除“新闻 - ”,并从链接.HTML,使URL干净,只是https://website.com/id

我尝试了好几种方法,但每次我碰上一个重定向循环。

**我试过几次把这里的代码,但失败了。因此,这里的链接配置文件https://jpst.it/1AKIf

html nginx nginx-location nginx-config
2个回答
0
投票

试试这个配置。

server {
    location / {

        # Redirects to the version without .html
        if ($request_uri ~ ^/(.*)\.html$) {  return 302 /$1;  }

        # Tries the uri, .html file and the news prefix.
        try_files $uri $uri/ $uri.html news-$uri news-$uri/
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.