【发布时间】:2019-01-25 13:58:16
【问题描述】:
根据 Laravel 的official docs,您可以通过将所述视图添加到资源/视图/错误并将文件命名为 [httpcode].blade.php 来显示给定 HTTP 响应的自定义 Blade 视图。我已经为 404 错误执行了此操作,每当遇到 404 错误时,Laravel 都会显示此视图。但是,当遇到 403 错误时,Laravel 会显示默认的、丑陋的 Apache 403“禁止”错误页面。
我的“大师”刀片布局(master.blade.php):
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="description" content="SQLess is a database management application.">
<title>{{ $title }}</title>
<link rel="stylesheet" href="{{ asset('css/bootstrap.min.css') }}">
@stack('css-extras')
@stack('scripts-extras')
</head>
<body>
@yield('content')
</body>
</html>
我的自定义 403 布局(403.blade.php):
@extends('master', ['title' => "Forbidden"])
@section('content')
<div>You shouldn't be here. This is a 403 error!</div>
@endsection
为什么这不起作用?
【问题讨论】:
-
检查您的apache logs 以确保它不是 apache 正在处理的实际目录权限问题。
-
@ourmandave Apache 日志显示:
[Sat Aug 18 22:37:33.078666 2018] [autoindex:error] [pid 7688:tid 1952] [client ip:51179] AH01276: Cannot serve directory C:/xampp/htdocs/sqless/public/img/: No matching DirectoryIndex (index.php,index.pl,index.cgi,index.asp,index.shtml,index.html,index.htm,default.php,default.pl,default.cgi,default.asp,default.shtml,default.html,default.htm,home.php,home.pl,home.cgi,home.asp,home.shtml,home.html,home.htm) found, and server-generated directory index forbidden by Options directive下一步是什么?