Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
禁用对index.php的直接访问,但将每个URI重定向到index.php/URI_Php_Apache_Url Rewriting - Fatal编程技术网

禁用对index.php的直接访问,但将每个URI重定向到index.php/URI

禁用对index.php的直接访问,但将每个URI重定向到index.php/URI,php,apache,url-rewriting,Php,Apache,Url Rewriting,我想禁用对/index.php的直接访问,但仍将其用作前端控制器(使用$\u服务器['PATH\u INFO'])。意思是: URI EXPECTED ACTION ----------------------------------------------- /index.php raise 404 / use /index.php/ /foo/bar use

我想禁用对
/index.php
的直接访问,但仍将其用作前端控制器(使用
$\u服务器['PATH\u 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)


谢谢你的帮助

如果您禁用对任何文件的访问,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

我希望能帮上忙……

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