我有一个PHP文件www.example.com/media.php 我也有一个在www.example.com同名的目录/media/manyotherfiles.phphtaccess:直接到php如果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文件链接到媒体目录中的页面)
如何使用我的.htaccess文件来做到这一点?到目前为止,我有这个删除PHP文件扩展名:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+?)/?$ $1.php [L]
Options -Indexes
而且,我目前工作的一个本地服务器上的测试目录,因此,例如,我的文件会是这样:
ip.address.here/beta/index.php
ip.address.here/beta/media.php
ip.address.here/beta/media/manyotherfiles.php
这并不工作 - ,我得到一个404未找到错误,当我现在尝试访问任何PHP文件除了FO r index.php。它说没有找到类似“/ media/manyotherfiles”的东西。 – Rookie94 2014-10-20 01:08:20
你可以在浏览器中打开“http:// domain.com/media/manyotherfiles.php”吗?确保这是规则之前的其他规则,它被放置在根.htaccess – anubhava 2014-10-20 03:39:43
是的,但我不能打开这样的PHP文件:'http:// domain.com/page.php'。尽管该文件在root权限。 – Rookie94 2014-10-20 14:46:46