【问题标题】:Error with routes in Laravel 5.0Laravel 5.0 中的路由错误
【发布时间】:2015-12-17 09:27:03
【问题描述】:

我在 Laravel 5.0 中使用路由时出现问题,我只需要调用这个路由:

Route::get('home', 'HomeController@index');

但是当我写http://localhost/course/public/home时浏览器会显示这个:

Not Found
The requested URL /course/public/home was not found on this server.
Apache/2.4.9 (Win64) PHP/5.5.12 Server at localhost Port 80

如果我写http://localhost/course/public/ 索引有效,但其他路线无效,我不知道为什么。

在我的 Routes.php 中有这个:

Route::get('/', 'WelcomeController@index');

Route::get('home', 'HomeController@index');

Route::controllers([
    'auth' => 'Auth\AuthController',
    'password' => 'Auth\PasswordController',
]);

我只用composer下载了laravel 5.0,下载后代码没有做任何改动,我只想测试路由,这些都不行。

感谢您的帮助。

【问题讨论】:

  • 是否有名为“public”的控制器?
  • 你好 Gaurav Dave,控制器的名字是“HomeController”,public是索引所在的文件夹。
  • 从 url 中删除 public 并转到 /course/home
  • 我做到了,但错误是一样的。

标签: php laravel laravel-5


【解决方案1】:

总之(cmets 解决了这个问题,所以谢谢你们!!)你可能在 Apache 上运行 Laravel,但你没有启用 mod_rewrite... 或者没有正确配置。

Laravel 使用所谓的漂亮 url。为了实现这一点,每个请求都被重写,并且您可以在公共文件夹的 .htaccess 文件中找到配置。这给出了一个快速而肮脏的解释,让你编写没有index.php 的 URL。

此外,您的服务器应该服务于公用文件夹而不是主文件夹。如果您想在生产环境中使用您的网站,这是一个安全问题。

或者,您可以使用 nginx,在我看来它更容易配置,如果您运行 laravel homestead,一切都直接开箱即用。

【讨论】:

    猜你喜欢
    • 2017-10-09
    • 2015-07-26
    • 1970-01-01
    • 1970-01-01
    • 2015-09-25
    • 1970-01-01
    • 2018-01-18
    相关资源
    最近更新 更多