I have a very simple MVC project (no DB) that works very well when I launch it with a local server ("php -S localhost:8000 -t public").
I use my routing this way:
require "Controllers/AppController.php";
$parsed_url = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$appController = new AppController();
switch ($parsed_url) {
case '/':
case '/home':
$appController->home();
break;
case '/about':
$appController->about();
break;
case '/achievements':
$appController->achievements();
break;
case '/contacts':
$appController->contacts();
break;
default:
$appController->pageNotFound();
I deployed it with Heroku, adding a Procfile, as specified in the official documentation, but now I can only get the homepage of my portfolio. All my other links throw me a "Not Found - The requested URL was not found on this server.".
Here's my Heroku log, if that can help:
2022-10-30T09:26:48.666806+00:00 heroku[router]: at=info method=GET path="/about" host=alexis-boucherie-devweb.herokuapp.com request_id=0dd695f8-8252-4cd4-8d3d-e012daf06130 fwd="86.213.16.43" dyno=web.1 connect=0ms service=1ms status=404 bytes=360 protocol=https
What I don't understand, is that if I try to var_dump my "$parsed_url", it does return a "/", for the homepage. So I think it means the program goes through my Switch Case and that my Controller is ok. Also, because I have my homepage showing in the first place.
I tried to modify the page my $appController object calls for, and by doing so, I can access another page. But then again, if I click on any link or manually type the address of one of my pages (for instance "/contacts"), it doesn't work.
In the end, I tried and searched for other topics related to this, found two here on StackOverflow, about adding an .htacess file, but I'm not sure I'm getting how that really works. Could this be the real source of my problem?