Description
PHP Version
8.3
CodeIgniter4 Version
4.6.1
CodeIgniter4 Installation Method
Composer (using codeigniter4/appstarter
)
Which operating systems have you tested for this bug?
Linux
Which server did you use?
apache
Database
No response
What happened?
I have a codeigniter 4 app that has to live in a shared hosting enviroment and has to be in a subdirectory.
The app has been developed with legacy autorouting enabled.
The app has indexPage as index.php
All the autorouting routes end up throwing a 404 with the "index.php is not a valid controller name" statement.
Steps to Reproduce
- get an apache webserver
- set
indexPage
asindex.php
in your app/Config/App.php - install codeigniter in a subdirectory:
/var/www/html/code-igniger-app
/var/www/html/other-apps-here
this way you'll access the app from http://localhost:8080/code-igniger-app/index.php
4. enable legacy autorouting and create a controller
Expected Output
It should not be throwing a 404
Anything else?
To fix it i added the following code to the very beginning of the index.php
$_SERVER["SCRIPT_NAME"] = str_replace("/public","",$_SERVER["SCRIPT_NAME"]);
The SCRIPT_NAME would have been: /code-igniger-app/public/index.php
this way it becomes /code-igniger-app/index.php
.
This way when CodeIgniter\HTTP\SiteURIFactory
uses the parseRequestURI
method to remove the SCRIPT_NAME
form the uri and then return the $path
it is able to return it correctly.