【问题标题】:How to remove .php and .html to URLs and add trailing slash in Nginx?如何删除 .php 和 .html 到 URL 并在 Nginx 中添加斜杠?
【发布时间】:2018-05-24 14:42:20
【问题描述】:

我有一个包含 faq.html 页面和 where-to-buy.php 页面的登录页面。我想从 URL 的末尾删除 .html/.php 并为所有 URL 添加一个尾部斜杠。所以:

www.website.com/faq.html -> www.website.com/faq/

www.website.com/where-to-buy.php -> www.website.com/where-to-buy/

如何在 Nginx 中做到这一点?谢谢。

【问题讨论】:

    标签: nginx url-rewriting


    【解决方案1】:

    这是一个有点复杂的问题,有很多方法可以做到这一点,其中最简单的方法是将所有文件转换为索引文件。

    假设你的目录结构是这样的,

    www/faq.html

    www/where-to-buy.php

    你可以改成

    www/faq/index.html

    www/where-to-buy/index.php

    这将解决问题......但这可能不是最好的答案,这取决于您如何构建它,以及您希望在未来如何维护它

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-04
      • 1970-01-01
      • 1970-01-01
      • 2016-07-02
      • 1970-01-01
      • 2012-03-18
      • 2017-05-27
      • 2018-11-22
      相关资源
      最近更新 更多