【问题标题】:What is a mod_rewrite rule to turn *.html to *.php?将 *.html 转换为 *.php 的 mod_rewrite 规则是什么?
【发布时间】:2010-03-07 00:04:21
【问题描述】:

我需要一个重写器,所以如果我输入 index.html 我会显示 index.php

我的意思是我有 home.php、about.php 之类的文件,我也希望能够使用 .html 访问它们

提前致谢

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite


    【解决方案1】:

    最简单的解决方案:

    RewriteRule ^(.*)\.html$ $1.php
    

    要支持htmHTMLhTmL等,请使用:

    RewriteRule ^(.*)\.html?$ $1.php [NC]
    

    【讨论】:

    • 如果在原始 URL 的查询字符串中找到 .html,这将匹配。例如,/somepage.php?url=x.html 将匹配,尽管它可能不是预期的行为。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-27
    • 1970-01-01
    • 2011-01-27
    • 2017-09-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多