I have used Slim Framework several times without any problem but now I’m trying to set a route to match URL that ends with .html and render a certain view, but the framework return a 404 Not Found error, the route is ignored and it seems to me that just checks if there is a file named like that, and since there isn’t, simply throw the 404.
The route I’m trying to set is this:
$app->get('/{slug}.html', BusinessController::class . ':business');
This is possible in Laravel and that’s the reason I’m a bit confused. Maybe someone stumbled upon this issue and know a solution.
Advertisement
Answer
Firstly to achieve this you will need to disable your web server (apache, nginx or other) from serving static html pages for your project. Typically a url that ends with .html will cause web servers to check for the corresponding static html file.
Then you need to add rewrite logic in .htaccess
file to make sure all *.html
routes are passed to your frameworks route handler like index.php
or server.php
(I am not familiar with Slim). Then its a matter of how you have configured your framework to handle there routes.