与xampp的Laravel 404错误

时间:2017-09-08 10:03:18

标签: laravel

我开始学习如何使用laravel但遇到了问题。当我去:http://localhost/testing/public/我得到一个工作页面,但当我打字例如http://localhost/testing/public/home这是我的一个观点时,我得到404错误。有人知道如何解决这个问题吗?

编辑: 我正在使用最新版本的laravel,例如:

Route::view('/home', 'home');

在我的routes / web.php中,我收到了该错误

3 个答案:

答案 0 :(得分:2)

这更可能是虚拟主机的问题,请尝试以下方法:

  • 首先修改您的路线:Route::get('/home', function(){echo "hello"});
  • 然后尝试访问:http://localhost/testing/public/index.php/home

如果它有效,那肯定是因为你没有虚拟主机,你可以在你的Xampp配置中轻松设置它并修改你的主机文件

  • 首先转到C:\Windows\System32\drivers\etc\hosts并添加新内容 如:127.0.0.1 yoursite.local
  • 然后转到安装xampp的地方 xampp\apache\conf\extra\httpd-vhosts.conf
  • 然后在文件底部添加一个虚拟主机,如:
  

<VirtualHost *:80>

DocumentRoot "PATH_to_laravel_folder/public"  

ServerName yoursite.local  
     

</VirtualHost>

  • 然后您可以输入以下内容来访问您的路线:yoursite.local/home或 yoursite.local:80 /家

希望它可以帮助你们:)

答案 1 :(得分:0)

可能是因为路线。 创建视图后,您必须在routes/web.php

中添加它

与5.5版本中的Route::view('/yourUrl', 'viewName');类似。 对于5.4或更早版本Route::get('/yourUrl', 'viewName');

将此添加到routes / web.php后

。您可以访问http://localhost/testing/public/yourUrl

您可以找到更多here

答案 2 :(得分:0)

如果http://localhost/testing/public/index.php/home 有效,请尝试在 public 中创建一个 .htaccess 文件> 目录:

RewriteEngine On
RewriteBase /testing/public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]