【问题标题】:Laravel routes does not workLaravel 路线不起作用
【发布时间】:2017-10-02 07:41:01
【问题描述】:

当我写这篇文章时Route::get('/', 'Login@index');

并使用网址

http://localhost/laravel-4.2.11/blog/”有效,

但是当我使用这个Route::get('home', 'Login@index');

和 url "http://localhost/laravel-4.2.11/blog/home" 它给出 404 错误

【问题讨论】:

    标签: php url laravel-5 laravel-4 routes


    【解决方案1】:

    第一

    您应该检查错误日志文件中的内容,通常在

    存储/日志/laravel.log

    https://laravel.com/docs/5.4/errors

    这应该为您提供有关此 URL 为何找不到它的信息。

    第二

    请检查您的网络服务器上的配置:

    https://laravel.com/docs/5.4/installation#web-server-configuration

    阿帕奇

    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    

    Nginx

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    

    第三

    请报告本次测试的结果...

    【讨论】:

      【解决方案2】:

      如果你想同时使用 / 和 /home 作为主页,

      Route::get('/{home?}', 'Login@index');
      

      或者你可以写成两个,

      Route::get('/', 'Login@index');
      Route::get('home', 'Login@index');
      

      【讨论】:

      • 用这个Route::get('home', 'Login@index');是不行的
      • 我的意思是你应该保留这两个 Route::get('/', 'Login@index'); Route::get('home', 'Login@index');,不只是一个当你想使用Route::get('home', 'Login@index');
      • 显示项目根目录的配置,例如 apache2 的 DocumentRoot
      【解决方案3】:

      尝试使用前面的/ 更改您的路线,如下所示:

      Route::get('/home', 'Login@index');

      虽然这不是它的记录方式,但它在许多项目中都适用于我。

      【讨论】:

        猜你喜欢
        • 2013-05-03
        • 2014-09-08
        • 2015-03-18
        • 2017-12-13
        • 2017-02-27
        相关资源
        最近更新 更多