-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
404 File not found error when running CodeIgniter on local Apache web server and virtual hosts #1391
Comments
If codeigniter.test is a virtual host mapped to htdocs/CodeIgniter4.public, then the base URL for that will be http://codeigniter.test, and the same would be used in your browser! You are not using the virtual hosting correctly. Your description is looking for application/Controllers/CodeIgniter4.test/Standard, naturally leading to a 404. |
Hi Jim-Parry, sorry, that was a typo. I meant http://codeigniter.test. The bug occurs whenever $uri starts and/or ends with a '/'. |
Ok - so your virtual hosting is setup properly, and with application/Config settings
and with application/Config/Routes settings
and your Standard controller is in the right namespace, The setDirectory method you mention adds a trailing slash to the original one with any trailing slash removed, i.e. it ensures that there is a single trailing slash at the end of the directory name containing the controller . This sounds to me like it is specifically trying to avoid the situation you describe. You mention |
Oops - I see you have opened a different problem report :-/ |
I am running locally an Apache web server and use virtual hosts (example name: CodeIgniter4.test). The document root is set to /CodeIgniter4/public. The base URL in App.php is therefore set to:
http://localhost/CodeIgniter4/public/
A controller "Standard" is defined and in Routes.php the following default settings exist:
$routes->setDefaultController('Standard'); $routes->setDefaultMethod('index');
There are no route definitions!
Trying to call http://localhost/CodeIgniter4.test in a browser leads to 404 File not found error which is not correct.
The reason for the error can be found in the validateRequest method of class Router: the parameter $segments contains in this case two string elements of size zero (empty strings). The reason is that autoRoute is called with the URI '/'.
Line 578 of Router.php reads:
if ( ! file_exists(APPPATH . 'Controllers/' . $test . '.php') && $directory_override === false && is_dir(APPPATH . 'Controllers/' . $this->directory . ucfirst($segments[0]))
where $directory_override is false and $this->directory and $test are initially empty.
This means that for the first test
is_dir(APPPATH . 'Controllers/' . $this->directory . ucfirst($segments[0])
is true and the directory is set to '/'.Unfortunately, it seems to be that the same test is also true when $this->directory has the value '/'. In this case the parameter of is_dir is something like APPPATH.'Controllers//' and still is_dir returns true (I am using PHP 7.1.19).
So, finally $this->directory contains '//', which is of course not correct. This means that the controller's name is "App\Controllers\\Standard". And a file relating to this controller does not exist and hence the 404 File not found exception is thrown.
PS: I am using CodeIgniter 4 version Alpha2, PHP 7.1.19.
The text was updated successfully, but these errors were encountered: