Skip to content

Bug: codeigniter in a subdirectory + indexPage results in 404 #9602

Closed
@Franky5831

Description

@Franky5831

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

  1. get an apache webserver
  2. set indexPage as index.php in your app/Config/App.php
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions