Regarding the routing problem of PHP's Laravel framework, please ask the expert for answers.
天蓬老师
天蓬老师 2017-06-30 09:52:44
0
5
898

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

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(5)
学霸

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

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ / [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

nginx

typecho

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template