CodeIgniter4
CodeIgniter4 copied to clipboard
Bug: URI `*.php` shows `/` page
PHP Version
8.0
CodeIgniter4 Version
develop
(edb894f2fde3eac146094eb3e5e0491a62d47f96)
CodeIgniter4 Installation Method
Git
Which operating systems have you tested for this bug?
macOS
Which server did you use?
cli-server (PHP built-in webserver)
Database
No response
What happened?
The following URLs show the Welcome page: http://localhost:8080/a.php http://localhost:8080/b.php http://localhost:8080/c.php http://localhost:8080/test/a.php
Steps to Reproduce
Install CI4 and run php spark serve
.
Expected Output
Shows 404 page.
Anything else?
No response
system/Commands/Server/rewrite.php
- If we use
mod_rewrite
then the value of$_SERVER['SCRIPT_NAME']
will always be/index.php
- Lost dependency on
Config\App::$indexPage
.
I think it should look something like this.
$script = 'We need to get the value of Config\App::$indexPage';
$_SERVER['SCRIPT_NAME'] = '/' . $script ?? 'index.php';
require_once $fcpath . $script;
Because if the entry point is overridden, then the development server will not start.
I have a question is how URL with .php work normally.
Is it parsing the file and show if that file exist in public
folder?
Basically, I think http://localhost:8080/a.php
is http://localhost:8080/index.php/a.php
.
So CI4 handles the request.
But you can configure your web server to show if that PHP file exists in public
folder.
Oh, I got it.
I found that the problem can be solved by adding this line $_SERVER['SCRIPT_NAME'] = '/index.php';
at system/Commands/Server/rewrite.php
as @iRedds says.
But I'm not sure that getting the value of Config\App::$indexPage
is needed and possible.
As Config\App::$indexPage
doc shows:
If you are using mod_rewrite to remove the page set this variable so that it is blank.
Does this Config\App::$indexPage
variable not to be used at using mod_rewrite
in before design?
Config\App::$indexPage
is used when CI4 generates the site URLs.
If you configure the web server to be accessible without index.php
, you should set it ''
.
So this issue can be solved by adding this line $_SERVER['SCRIPT_NAME'] = '/index.php';
at system/Commands/Server/rewrite.php
?
I have been tested and this solution is useful.
If we use mod_rewrite then the value of $_SERVER['SCRIPT_NAME'] will always be /index.php
Yes.
And if we nagivate http://localhost/test/a.php
, we will see:
404 - File Not Found Can't find a route for 'get: test/a.php'.