I just started a course of implementing MVC pattern using PHP and I think I’m experiencing a bug regarding friendly URL engine. The site I’m creating has the follow URL syntax: http://[site]/[controller]/[method]/[parameters] .
Until now it works in a very simple way: I access a controller and is printed on screen which controller is beeing accessed (printed by a method from controller’s class). The problem is that when I access the URL http://cursophp/cliente (a real controller) it works and when I try an inexistent controller WAMP shows an error screen that informs that the page couldn’t be found; but, when I try to access http://cursophp/produto (also a real controller), an 404 error from Apache is exhibited! And I also tried with other words like: produto1, produto2, product, product1 (“prod” prefix) and the same 404 error is exhibited!
Using Composer or including directly the controller file with “require” results in the same problem.
Is it a known bug or am I making a mistake?
htacess content:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !f
RewriteCond %{REQUEST_FILENAME} !d
RewriteRule ^(.*)$ index.php/$1 [L]
Just adding more details:
When I try “pro” as controller’s name:
When I try “prod” (or any word with “prod” prefix):
When I try “aaaa” (or any word, of any length, that doesn’t correspond to a controller’s name):
2
Answers
The problem is probably in function that checking the route. Try to debug on which line it’s starting show the error. However, it’s impossible to suggest you a specific way of solving this problem without providing more details
This PHP script is crappy, because it does not handle unknown controllers properly.
Instead it should respond with
HTTP404
, when the file to load cannot be located.Generally speaking, you’d need to fix that in file
Core.php
.