出于某种原因,我的未经授权的路线为我的Laravel项目显示了404:
<?php
Route::group(['middleware' => 'auth'], function () {
Route::resource('bookings', 'BookingController');
Route::get('bookings.export', 'BookingController@export')->name('bookings.export');
});
Auth::routes();
Route::get('/', function () {
return redirect('/dashboard');
});
Route::get('/bookings/contract', 'BookingController@contract')->name('contract');
当我尝试访问/bookings/contract
时,出现404错误。这很奇怪,因为如果我尝试访问bookings.export
它就可以了。
我在共享主机上,因此我无法访问虚拟主机,我的.htaccess文件中包含以下内容:
DirectoryIndex index.html index.htm default.htm index.php index.php3 index.phtml index.php5 index.shtml mwindex.phtml
AddHandler application/x-httpd-php71 .php .php5 .php4 .php3
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
# Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
任何人都知道这里发生了什么?
答案 0 :(得分:0)
由于Route::group
中包含Resource
booking
路由,因此laravel会尝试查找该组中的所有booking
路由。
要使用具有booking
前缀的其他路线,请将其置于Route::group