【问题标题】:custom error pages not to be accesible directly自定义错误页面不能直接访问
【发布时间】:2013-08-31 23:13:25
【问题描述】:

在我的 .htaccess 中,我执行以下操作

then php 脚本将用户带到相关页面/显示相关文本

ErrorDocument 400 /error.php?e=400
ErrorDocument 401 /error.php?e=401
ErrorDocument 403 /error.php?e=403
ErrorDocument 404 /error.php?e=404
ErrorDocument 500 /error.php?e=500
ErrorDocument 503 /error.php?e=503

对于一些错误,我正在尝试发送一封自动电子邮件。

1)如果不是来自 apache,我如何防止页面被直接访问,例如仅通过键入 error.php?e=503 的人来访问

2)如何获取上次访问的 url(触发错误的 url?

谢谢

【问题讨论】:

    标签: php apache .htaccess apache2 errordocument


    【解决方案1】:

    (1)通过httpd.conf启用mod_rewrite和.htaccess,然后将此代码放在DOCUMENT_ROOT目录下的.htaccess中:

    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /
    
    ErrorDocument 400 /error.php?e=400
    ErrorDocument 401 /error.php?e=401
    ErrorDocument 403 /error.php?e=403
    ErrorDocument 404 /error.php?e=404
    ErrorDocument 500 /error.php?e=500
    ErrorDocument 503 /error.php?e=503
    
    # block direct access to /error.php
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+error\.php[\s?] [NC]
    RewriteRule ^ - [F]
    

    (2)/error.php 内部使用:

    $_SERVER["REQUEST_URI"];
    

    【讨论】:

      猜你喜欢
      • 2022-01-13
      • 1970-01-01
      • 2012-01-18
      • 2020-10-08
      • 2016-01-17
      • 2013-05-06
      • 2014-11-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多