【问题标题】:How could I configure Apache to display file names as directories instead?我如何配置 Apache 以将文件名显示为目录?
【发布时间】:2015-04-23 15:46:50
【问题描述】:

例如,我宁愿 CreateAccount.php 在客户的角度显示为 http://www.example.com/CreateAccount/。我知道创建很多目录并用index.php 填充每个目录很容易,但我宁愿做最有效的事情。首先,使用这种方法需要高度无组织和不必要的复杂组织标准。其次我也宁愿充分利用Apache的特性,即mod_rewrite

我知道有mod_rewrite。我已经开始阅读该模块的文档,但很快我就非常感到困惑和沮丧,因为我患有多动症,所以当我知道自己不懂时很难坐下来阅读我在读什么。

您能帮我找到最好的方法吗?

【问题讨论】:

    标签: apache .htaccess url mod-rewrite


    【解决方案1】:

    处理 mod_rewrite 的最佳方法是创建一个测试服务器/虚拟主机并慢慢构建您的配置。另外,尽量让你的初始规则非常简单,这样你就可以准确地理解每条规则的作用。此配置可以帮助您开始您的流程。最后一条规则是您需要将 CreateAccount/ 路径映射到 CreateAccount.php 脚本。

    <IfModule mod_rewrite.c>
        RewriteEngine On
    
        # You can use this only inside of the Directory directive or in the .htaccess file.
        RewriteBase /
    
        # http://www.example.com/page.html to redirect to http://www.example.com/page.php 
        RewriteRule ^(.*).html /$1.php [L]
    
        # http://www.example.com/mypath/page.html to redirect to http://www.example.com/mypath/page.php 
        RewriteRule ^mypath/(.*).html /mypath/$1.php [L]
    
        # http://www.example.com/CreateAccount/ to redirect to http://www.example.com/CreateAccount.php 
        RewriteRule ^(.*)/ /$1.php [L]
    </IfModule>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-16
      • 2014-09-17
      • 2012-01-15
      相关资源
      最近更新 更多