簡體   English   中英

禁止直接訪問index.php,但將每個URI重定向到index.php / URI

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM