php - 403错误处理

标签 php .htaccess url-routing http-status-code-403

我有一个用 PHP 编写的基本 Web 应用程序,我希望保护它,该应用程序位于本地 Web 服务器上。

当使用以下 url 字符串时:

http://localhost/test/index.php%20and%20substring(database(%20),1,1)=%22a%22

应用程序正在输出以下错误消息:

403

我希望网页显示“提供的 URL 不存在”之类的消息

我创建了一个 .htaccess 文件并将其放入包含以下内容的目录中:

enter image description here

但我仍然面临提供文件结构、我正在使用的服务器以及它正在通信的端口的错误。

我做错了什么?

最佳答案

要允许 ErrorDocument,您需要将 AllowOverride 设置为 All。例如,这是我的 virtualhost 文件:

<VirtualHost *:80>
    ServerName localhost
    ServerAlias php.local
    ServerAlias sub.php.local

    LogLevel debug

    DocumentRoot /var/www/projects/php

    <Directory /var/www/projects/php>
    DirectoryIndex index.php
        AllowOverride All
        Order Allow,Deny
        Allow from All
    </Directory>

</VirtualHost>

您也可以将 AllowOverride 设置为 FileInfo 以使用 ErrorDocument

另见 https://httpd.apache.org/docs/2.4/custom-error.html

关于php - 403错误处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33679326/

相关文章:

javascript - 当页面忙于加载时,新标签页自动打开?

php - 使用 PHP 在 $_SESSION 变量中存储多个值

php - 获取 google chrome 以查看 rss 提要

PHP 存储变量

Angular2 路由,路由参数

ASP.NET 友好 URL

php - 重写 url 在 htaccess 中不起作用

apache - htaccess 从基本身份验证中排除一个 url

php - .htaccess 不适用于 php 包括

javascript - 在 Backbone.MarionetteJS 中使用 appRouter