CodeIgniter Forums
Strange 404 routes when having a specific file in /public/ - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Strange 404 routes when having a specific file in /public/ (/showthread.php?tid=87063)



Strange 404 routes when having a specific file in /public/ - b126 - 03-10-2023

Here's a problem that's easy to cope with but still strange to me.

Say I have a presenter route defined as follows in /Config/Routes.php

PHP Code:
$routes->presenter('products', ['controller' => 'ProductsController']); 

and at the same time I have a products.txt file located in /public/ folder.

When I try to access /products/show/1 route I get a 404 Not Found.

I understand that the routes are created automatically and managed behind by the webserver but why is the .TXT not taken into account to differentiate the route and the file?


RE: Strange 404 routes when having a specific file in /public/ - iRedds - 03-10-2023

php routing starts working if the resource specified in the url does not exist.

For url example.com/products.txt
the server will first look for the public/products.txt file, and if the file is not found, the server will pass control to the framework's routing.

For url example.com/products/show/1
first, the server will look for the file public/products/show/1, and if the file is not found, the server will pass control to the framework's routing.

If you get a 404 for /products/show/1, then there is no "public/products/show/1" file, or there is no "ProductsController" controller, or there is no "show" method in this controller, or this method returns 404.
Or your web server is not configured.


RE: Strange 404 routes when having a specific file in /public/ - b126 - 03-19-2023

Quote:Many thanks for your accurate reply