1

我想禁用直接访问/index.php但仍将其用作前端控制器(使用$_SERVER['PATH_INFO'])。意义:

URI                    EXPECTED ACTION
-----------------------------------------------
/index.php             raise 404
/                      use   /index.php/
/foo/bar               use   /index.php/foo/bar
/index.php/foo/bar     raise 404

当时我使用以下.htaccess文件:

RewriteEngine On
RewriteRule ^ index.php [QSA,L]

我不需要任何其他文件index.php(制作 API)。

谢谢您的帮助!

4

2 回答 2

0

如果您禁用对任何文件的访问,apache 将对其进行限制,如果文件没有访问权限,则将被禁用。您可以使用 mod_rewrite 伪造一个 url 以在 URL 中显示 index.php,但您需要对其他文件执行其他操作。

index.php -- not access
index.php/foo/bar -- no access
test.php -- have access
test.php/foo/bar -- you can fake it in url throw mod_rewrite and result will looks like as index.php/foo/bar

我希望有帮助...

于 2013-02-04T18:53:58.273 回答
0

好吧,我不确定这是否可行,但值得一试吗?您可以为输入 /index.php 的任何人创建重写规则,并将其重写为服务器上不存在的 html 文件(foo.html 或其他)。这应该会在找不到文件时导致 404 错误,但在未指定文件名时仍允许服务器使用其默认行为加载 index.php。

于 2013-02-04T23:34:12.560 回答