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
[Re-opened] 404 File not found when running CodeIgniter on local Apache web server and virtual hosts #1400
Comments
I added to tests/system/Router/RouterTest what I think to be a unit testcase following your description...
It passes. What am I missing? |
Hi, this test will also pass in my case but: The default setting in Config/Routes.php is So, when I modify the test to:
I get the result
Perhaps the default setting in Config/Routes.php confused me (or CodeIgniter 4?). |
The document root should be set to the root directory where you installed CodeIgniter 4 not the public folder. You map the public folder. I use vhosts also. |
@InsiteFX Hmm - I understand "document root" to be the mapping, i.e. pointing at the public folder within the "project root". In the above, document root should refer to the DocumentRoot directive inside the virtual hosting element, no? That points at the front ontroller path, i.e. the public folder. |
Hi Jim, yes in the vhost the public_html is the document root. But in phpStorm the root is were you installed CodeIgniter, but it will not see the index.php until I map it in phpStorm to the public_html folder. `#-------------------------------------------------------------- HTTPS:#-------------------------------------------------------------- |
@InsiteFX Phew - we do mean the same thing then :) |
Hi Jim,
C:\Windows\System32\drivers\etc\hosts Make sure that these are not remarked out 127.0.0.1 localhost also for vhosts I set the local up like this: 127.0.0.1 cms.local |
@InsiteFX Agreed - that would be easier, setting up a domain alias for their CI VM. |
a turn around fix, try to use htaccess ^^
|
At the time of defining the virtual host, include public folder in the directory tag. So there is no need to mention public folder in htaccess file. |
Is this still open? |
Jim, `#-------------------------------------------------------------- CodeIgniter 4 Testing#-------------------------------------------------------------- #-------------------------------------------------------------- Testing CI 4.0 Dev#-------------------------------------------------------------- <VirtualHost *:443> #-------------------------------------------------------------- |
I also commented 11 days ago regarding not facing any issue on any of the OS(mac mojave, ubuntu 18.04 and Windows 10 Pro) |
It sounds like this one is fixed :) |
Sorry, but there were indeed typos in the previous bug report (which is closed now) that have been corrected by this post.
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://CodeIgniter4.test/
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://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.
PPS: This bug exists whenever the internally used variable $uri begins and/or ends with a '/'.
The text was updated successfully, but these errors were encountered: