【问题标题】:Hiding the .html in a URL [duplicate]在 URL 中隐藏 .html [重复]
【发布时间】:2011-12-15 13:01:11
【问题描述】:

可能重复:
How to hide the .html extension with Apache mod_rewrite

如何隐藏网页上的 .html 结尾?

我想要这个:

http://www.exmaple.com/lorem.html

看起来像这样:

http://www.example.com/lorem/

我知道可以通过在里面创建一个带有索引页面的文件夹来做到这一点,但是有没有办法告诉服务器将“.html”呈现为“/”?

【问题讨论】:

标签: html


【解决方案1】:

如果您有 apache 网络服务器,请查看 .htaccess 的可能性。

【讨论】:

    【解决方案2】:

    对于启用了 mod_rewrite 的 apache 服务器,将 .htaccess 文件添加到根公共 html 文件夹中,内容如下:

    RewriteEngine On
    RewriteRule   ^lorem/?$  lorem.html
    

    这将使 example.com/lorem.html 中的内容在 example.com/lorem/

    上可用

    如果您想为所有以 A-Z、a-z、0-9 字符命名的 .html 文件制定一个通用规则,您可以按如下方式进行:

    RewriteEngine On
    RewriteRule   ^([A-Za-z0-9-]+)/?$  $1.html
    

    如果 anyfile 包含以下字符,这将使 example.com/anyfile.html 中的内容在 example.com/anyfile/ 上可用:A-Z、a-z、0-9

    你可能想更深入,所以我建议你阅读这个cheetsheet

    【讨论】:

      猜你喜欢
      • 2013-02-18
      • 2021-05-02
      • 1970-01-01
      • 2017-06-24
      • 1970-01-01
      • 1970-01-01
      • 2014-03-23
      • 2021-01-23
      • 2013-06-03
      相关资源
      最近更新 更多