问题
I am trying to create Admin controllers in the default controller folder. I have created "admin" folder in the "controller" folder.
In the routes file:
Route::get('/admin', 'admin/AdminController@showAdminIndex');
AdminController.php file:
namespace Admin;
class AdminController extends \BaseController {
public function showAdminIndex()
{
return "Hello World";
}
}
I get an error on the browser:
403 Forbidden
What went wrong?
回答1:
The problem is that you have an admin
subfolder in the public
directory. The .htaccess
that ships with Laravel only boots the application if no directory or file exists at the requested URI (that's why CSS and other assets still work)
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
You basically have two options here:
Rename either one, the route or the folder. If
public/admin
is for assets you could put it inpublic/assets/admin
for example.Change your
.htaccess
to not ignore folders for rewriting
Like:
# Handle Front Controller...
# RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]`
来源:https://stackoverflow.com/questions/28457280/laravel-admin-controllers-403-forbidden