Issue
It seems that there is a conflict between MAMP and Slim framework on my environment.
I am trying to learn Slim, and I have this weird situation where I can create a route for '/', but impossible to do it for '/contact'.
$app->get('/', \App\Controllers\PagesController::class . ':home');
$app->get('/contact', \App\Controllers\PagesController::class . ':getContact');
Slim seems to catch the / route, but when I type http://localhost:8888/contact/ in my browser Slim doesn't catch the request, I have a 404...
I tried to create a real "contact" folder with an index.html file inside, and of course then it works... it displays the index.html
Solution
You need to route all requests to the index.php
file. Mamp is looking for a directory structure that does not exist until you create it, as you did.
Create a .htaccess
file in the your app's root folder. and insert the following:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
if you are just learning php and slim then I recommend ditching MAMP and just using the integrated PHP server. From your project's folder, Kick off the server with the following CLI command:
PHP -S localhost:3000
Answered By - Scriptonomy
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.