Laravel,管理员控制器-禁止使用403 [英] Laravel, Admin controllers - 403 Forbidden

查看:42
本文介绍了Laravel,管理员控制器-禁止使用403的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在默认控制器文件夹中创建管理控制器.我已经在控制器"文件夹中创建了管理员"文件夹.

I am trying to create Admin controllers in the default controller folder. I have created "admin" folder in the "controller" folder.

在路由文件中:

Route::get('/admin', 'admin/AdminController@showAdminIndex');

AdminController.php文件:

AdminController.php file:

namespace Admin;

class AdminController extends \BaseController {

    public function showAdminIndex()
    {
        return "Hello World";
    }

}

浏览器出现错误:

403 Forbidden

出了什么问题?

推荐答案

问题是您在 public 目录中有一个 admin 子文件夹.Laravel附带的 .htaccess 仅在请求的URI上不存在目录或文件的情况下引导应用程序(这就是CSS和其他资产仍然起作用的原因)

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. 重命名一个路由或文件夹.如果将 public/admin 用于资产,则可以将其放在 public/assets/admin 中.

  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.

更改您的 .htaccess 以不忽略要重写的文件夹

Change your .htaccess to not ignore folders for rewriting

赞:

# Handle Front Controller...
# RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]`

这篇关于Laravel,管理员控制器-禁止使用403的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆