【问题标题】:Removing .html from a link using NGINX使用 NGINX 从链接中删除 .html
【发布时间】:2019-02-08 13:19:20
【问题描述】:

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

我想要做的是从链接中删除“news-”和 .html 并使用 https://website.com/id 使 url 干净

我尝试了几种方法,但每次遇到重定向循环。

**我尝试了几次将代码放在这里但失败了。所以这里是配置文件的链接https://jpst.it/1AKIf

【问题讨论】:

  • I have tried several methods 与我们分享这些

标签: html nginx nginx-location nginx-config


【解决方案1】:

试试这个配置。

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/
    }
}

【讨论】:

  • 谢谢。花了大约 3 个小时才找到它。
猜你喜欢
  • 2019-09-15
  • 1970-01-01
  • 2016-04-28
  • 2010-12-08
  • 1970-01-01
  • 1970-01-01
  • 2018-05-01
  • 1970-01-01
  • 2022-11-20
相关资源
最近更新 更多