【问题标题】:don't display .php extension in address bar(php)不要在地址栏中显示 .php 扩展名(php)
【发布时间】:2011-10-05 17:14:23
【问题描述】:

首先这个方法显然在 github 上工作,例如页面显示完成:

https://github.com/account
https://github.com/inbox

根本没有 .php 扩展名 + 不需要 ?page=account?page=inbox

在我看来,这是通过 .htaccess 完成的。

也许有人知道它应该是什么样子才能达到与 github 网站相同的效果?

【问题讨论】:

    标签: url url-rewriting


    【解决方案1】:

    这可以使用 apache 的 mod_rewrite 来实现

    您将 .htaccess 文件放在文档根目录中并为其指定规则(正则表达式)以匹配调用的 URL

    看起来类似这样:

    RewriteEngine On
    
    # rule to call MyPage.php if you call the URL http://yourdomain.com/MyPage
    RewriteRule ^(.*)$ $1.php
    
    # rule to add GET params
    RewriteRule ^(.*)$ index.php?page=$1
    

    网上有几个关于mod_rewrite的教程

    【讨论】:

      猜你喜欢
      • 2017-07-12
      • 1970-01-01
      • 2014-03-26
      • 1970-01-01
      • 2015-09-12
      • 1970-01-01
      • 2016-02-18
      • 2011-08-14
      • 1970-01-01
      相关资源
      最近更新 更多