【发布时间】:2014-10-19 16:36:38
【问题描述】:
我在 www.example.com/media.php 有一个 php 文件 我在 www.example.com/media/manyotherfiles.php 也有一个同名目录
如果我输入网址为 www.example.com/media 或 www.example.com/media/,我希望被定向到 www.example.com/media.php 上的文件,而不是里面的文件工作目录。 但是,如果我输入网址为 www.example.com/media/manyotherfiles,我希望被定向到 www.example.com/media/manyotherfiles.php。 (media.php 文件链接到 media 目录中的页面更直观)
如何使用我的 .htaccess 文件执行此操作?到目前为止,我已经删除了 .php 文件扩展名:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+?)/?$ $1.php [L]
Options -Indexes
另外,我目前正在本地服务器上的 beta 目录工作,例如,我的文件将是这样的:
ip.address.here/beta/index.php
ip.address.here/beta/media.php
ip.address.here/beta/media/manyotherfiles.php
【问题讨论】:
标签: php apache .htaccess mod-rewrite