[英]Disable direct access to index.php but redirect every URI to index.php/URI
我想禁用对/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)。
谢谢您的帮助!
如果您禁用对任何文件的访问,则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。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.