且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何修复 Laravel 5.1 - 404 Not Found?

更新时间:2023-02-22 14:45:27

当我第一次设置 Laravel 站点时,我看到能够访问/路由的相同行为,但所有其他页面返回 404.

I see the same behaviour of being able to visit the / route but all other pages return a 404 when I first setup Laravel sites.

在您的 apache 配置文件 httpd.conf 或 httpd-vhosts.conf 中,您需要启用可以放置在 .htaccess 文件中的指令.

In your apache config file httpd.conf or httpd-vhosts.conf you need to enable the directives that can be placed in the .htaccess file.

这是我的 VirtualHost 配置示例:

Here is an example of my VirtualHost configuration:

<VirtualHost *:80>
    ServerAdmin admin@gmail.com
    DocumentRoot "C:/www/laravel_authority-controller_app/public"
    ServerName authoritycontroller.www
    ErrorLog "logs/AuthorityController.www-error.log"
    CustomLog "logs/AuthorityController.www-access.log" common
    <Directory "C:/www/laravel_authority-controller_app/public">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks Includes ExecCGI

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
    </Directory>
</VirtualHost>

您的问题的关键条目是AllowOverride All.这应该足以让网站正常工作,但您还可以包含 optionsRequire all allowed 如果它们在整个网站中保持一致.

The key entry for your issue is AllowOverride All. This should be enough to get the website working but you can also include options and Require all granted if they are consistent across the entire website.