简体   繁体   中英

Disable direct access to index.php but redirect every URI to index.php/URI

I want to disable direct access to /index.php but still use it as a front controller (using $_SERVER['PATH_INFO'] ). Meaning:

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

At the time I use the following .htaccess file:

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

I do not have a need for any other file than index.php whatsoever (making an API).

Thank you for your help!

if you disable the access to any file, apache will be restrict it and if file have not an access so is disabled. You can use mod_rewrite to fake an url to display it index.php in URL, but you need to do other things with other file.

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

I hope so help ...

Well I am not sure this will work but it is worth a try? You could create a rewrite rule for anyone you enters the /index.php and rewrite it to an html file that does not exist on your server (foo.html or whatever). That should cause the 404 error when the file is not found but still allow the server to use its default behavior to load the index.php when no file name is specified.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM