Laravel 错误:“抱歉,找不到您要查找的页面”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49673743/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel error: "Sorry, the page you are looking for could not be found"
提问by Fabien Pittier
I need to update a website from a colleague to just add a LDAP connexion.
我需要从同事那里更新网站以添加 LDAP 连接。
I use EasyPHP devserver 17.0 with php 7.1.3 and MySQL 5.7.17.
我将 EasyPHP devserver 17.0 与 php 7.1.3 和 MySQL 5.7.17 一起使用。
I've read a lot of docs etc to be started and to recover the site in local as it is working actually.
我已经阅读了很多文档等以启动并在本地恢复站点,因为它实际上正在工作。
Everything was working so I began to add a login form etc... but when I tried to test a link from the website, it return me the error "Sorry, the page you are looking for could not be found". So I began to search on forums I found some results about routes etc and everything I've tested didn't worked.
一切正常,所以我开始添加登录表单等......但是当我尝试测试来自网站的链接时,它返回错误“抱歉,找不到您要查找的页面”。所以我开始在论坛上搜索我发现了一些关于路线等的结果,但我测试过的一切都没有奏效。
So, I decide to use the backup from the website as it was when I juste restore it in local(I precise link to other page and everything was working). I check the link and again, "Sorry, the page you are looking for could not be found". I decide to try another developement tool and download XAMP, exactly same error. I tried with Wamp, Laragon always same error.
所以,我决定使用网站上的备份,就像我在本地恢复它时一样(我精确链接到其他页面并且一切正常)。我检查了链接,然后再次“抱歉,找不到您要查找的页面”。我决定尝试另一个开发工具并下载 XAMP,完全相同的错误。我试过 Wamp,Laragon 总是同样的错误。
In the apache conf mod_rewrite is enabled.
在 apache conf mod_rewrite 中启用。
My laravel framework version is: 5.5.39
我的laravel框架版本是:5.5.39
So my folder look like:
所以我的文件夹看起来像:
The content of routes > web.php:
route > web.php 的内容:
Route::get('/', function () {
return view('welcome');
})->name('welcome');
// Holidays
Route::get('/holidays/create', 'HolidayController@create')->name('holidays.create');
Route::post('/holidays', 'HolidayController@store')->name('holidays.store');
Route::get('/holidays/{holiday}/delete', 'HolidayController@destroy')->name('holidays.destroy');
Route::get('/holidays/{holiday}/edit', 'HolidayController@edit')->name('holidays.edit');
Route::post('/holidays/{holiday}', 'HolidayController@update')->name('holidays.update');
// Leave types
Route::get('/types/create', 'TypeController@create')->name('types.create');
Route::post('/types', 'TypeController@store')->name('types.store');
Route::get('/types/{type}/delete', 'TypeController@destroy')->name('types.destroy');
Route::get('/types/{type}/edit', 'TypeController@edit')->name('types.edit');
Route::post('/types/{type}', 'TypeController@update')->name('types.update');
// Users
Route::resource('users', 'UserController');
Route::get('/births', 'UserController@getAllBirths')->name('births');
// Leaves
Route::get('/calendar', 'LeaveController@index')->name('calendar');
Route::post('/leaves', 'LeaveController@store')->name('leaves.store');
Route::post('/leaves/{leave}', 'LeaveController@update')->name('leaves.update');
Route::get('/leaves/{leave}/delete', 'LeaveController@delete')->name('leaves.delete');
Route::get('/leaves', 'LeaveController@getAll')->name('leaves');
Route::get('/config', 'ConfigController@index')->name('config');
// Stats
Route::get('/statistics', 'StatsController@index')->name('stats.index');
Auth::routes();
My virtualHost in Httpd.conf is:
我在 Httpd.conf 中的 virtualHost 是:
<VirtualHost 127.0.0.1>
DocumentRoot "C:/Users/sadm-m263733/Desktop/EasyPHP-Devserver-17/eds-www"
ServerName 127.0.0.1
<Directory "C:/Users/sadm-m263733/Desktop/EasyPHP-Devserver-17/eds-www">
Options FollowSymLinks Indexes ExecCGI
AllowOverride All
Order deny,allow
Allow from 127.0.0.1
Deny from all
Require all granted
</Directory>
</VirtualHost>
I don't know what I could do but please ask me if you need more information to help me.
我不知道我能做什么,但请询问我是否需要更多信息来帮助我。
If it can help; gitLab link from the site I'm trying to restore: https://gitlab.com/balsigergil/btplan
如果它可以提供帮助;来自我正在尝试恢复的站点的 gitLab 链接:https://gitlab.com/balsigergil/btplan
Further precisions: Auth routes is called twice, at first in the HomeControler.php: class HomeController extends Controller
进一步的精度:Auth 路由被调用两次,首先在 HomeControler.php 中: class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('home');
}
}
And then in the middleware RedirectIfAuthenticated.php :
然后在中间件 RedirectIfAuthenticated.php 中:
use Illuminate\Support\Facades\Auth;
class RedirectIfAuthenticated
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect('/home');
}
return $next($request);
}
}
Do you think I need to delete this part from the HomeController :
你认为我需要从 HomeController 中删除这部分:
public function __construct()
{
$this->middleware('auth');
}
And this part from the middleware:
而这部分来自中间件:
if (Auth::guard($guard)->check()) {
return redirect('/home');
}
I've delete the auth routes in Routes/web.php
我已经删除了 Routes/web.php 中的 auth 路由
回答by SystemGlitch
Change your VirutalHost DocumentRoot so the root is the public
directory.
更改您的 VirutalHost DocumentRoot,使根目录成为public
目录。
DocumentRoot "C:/Users/sadm-m263733/Desktop/EasyPHP-Devserver-17/eds-www/siteBTPlan/public"
回答by Peter Estiven
The root for Laravel is not the root of your Laravel folder. You need to setup your document root to the Laravel public
folder.
Laravel 的根目录不是 Laravel 文件夹的根目录。您需要将文档根目录设置为 Laravelpublic
文件夹。
DocumentRoot "<your-laravel-path>/public"
回答by SystemGlitch
As you're not using authentication for you application, remove the auth
middleware from your controller and this will be good.
由于您没有为应用程序使用身份验证,因此请auth
从控制器中删除中间件,这会很好。
$this->middleware('auth'); //Remove this line