I have defined the following routes in routes/wen.php:
When I access public/index.php, I can enter the Index method in the Index controller normally. At this time, my domain name is: 127.0.0.1/Laravel/public. Because of the apache configuration, index.php is opened by default only in It is not displayed in the domain name,
but I defined the second route, which is user in the root directory. At this time, I accessed 127.0.0.1/Laravel/public/user again
and the following error occurred
When I added index.php to 127.0.0.1/Laravel/public/index.php/user, it was accessible normally. I don’t understand why.
Why when I watched the video tutorial, others accessed it directly. Yes, no need to add index.php
There is a problem with apache's rewrite configuration. URL rewriting failed.
I always locate the public directory directly in nginx or apache, which means that public/index.php will be automatically accessed
Basically, it is definitely due to url rewriting. I also encountered it a few days ago. I followed the tutorial and wrote 127.0.0.1/Laravel/public/user and reported an error. I had an idea and just changed it to 127.0.0.1/Laravel/publicindex.php//user. . For this kind of thing, the poster doesn't have to fight hard, it's a waste of time, just know the principle. After learning, many problems will be solved easily!
Add route redirect
Apache
nginx
What the master above said is correct, but I wonder if your distributed configuration file in the public folder is gone. Can you check if there is an .htaccess file? Speaking of which, it is impossible to modify the public folder. You can skip index.php when accessing it, so I suggest you check if there is any problem with this file.