Laravel, Admin controllers - 403 Forbidden

你。 提交于 2020-06-25 05:58:16

问题


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:

  1. Rename either one, the route or the folder. If public/admin is for assets you could put it in public/assets/admin for example.

  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!