简体   繁体   English

Laravel 5.3路由不起作用

[英]Laravel 5.3 route not working

I have installed fresh copy of laravel 5.3. 我已经安装了laravel 5.3的新副本。

I have the following code in my route/web.php . 我的route/web.php有以下代码。

Route::get('/', function () {
    return view('welcome');
});

Route::get('welcome', function () {
    return view('welcome');
});

when i hit localhost/project/public in the browser i can see laravel welcome page. 当我在浏览器中点击localhost/project/public时,我可以看到laravel欢迎页面。

But when i hit localhost/project/public/welcome then 404 Not Found comes up where i should get the same laravel welcome page. 但是,当我点击localhost/project/public/welcome 404 Not Found ,我应该获得相同的laravel欢迎页面。

Am i forgetting something ? 我忘记了什么吗?

Laravel不区分大小写,因此如果使用其中之一创建项目,将找不到路径。

I was having some trouble with this myself, so for anyone having trouble with getting a Laravel route to work: 我自己对此有一些麻烦,因此对于任何在Laravel上班路上遇到麻烦的人来说:

  1. Make sure your route is defined the correct way by running php artisan route:list Your route should show up, along with the method. 通过运行php artisan route:list确保您的路由定义正确,该路由应与方法一起显示。 (get, post, ...) (获取,发布,...)
  2. Enable mod_rewrite from the Apache settings so Laravel can map /uri to whatever you like. 从Apache设置启用mod_rewrite ,以便Laravel可以将/ uri映射到您喜欢的任何内容。
  3. Modify the .htaccess or Apache settings to allow url overrides: AllowOverride All If you are working on something like localhost/~username/yourproject , also check the username.conf file in /private/etc/apache2. 修改.htaccess或Apache设置以允许url覆盖: AllowOverride All如果您正在使用localhost/~username/yourproject ,还请检查/ private / etc / apache2中的username.conf文件。

I'm not an expert in Apache settings, so feel free to correct or elaborate where needed. 我不是Apache设置方面的专家,因此随时可以在需要时进行更正或详述。

Has your route file been cached? 您的路线文件是否已缓存? See what happens when you run: 查看运行时发生的情况:

php artisan route:clear

and try again. 然后再试一次。

goto htaccess in your laravel folder after ( RewriteEngine On ) add this 在(RewriteEngine On)添加后在您的laravel文件夹中转到htaccess

RewriteBase  /yourlaravel project name/public

example: 例:
RewriteBase /laravel/public RewriteBase / laravel /公共

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM