dotif64826 2015-03-04 21:15
浏览 38
已采纳

你如何通过htaccess获得自定义401 Unauthorized页面

So I have a Password Protected Localhost Server to prevent these unknown IPs from getting in my server.

What I want to do is as soon as they try logging in and they get a 401 error htaccess sends them to a file called block.php

as so: ErrorDocument 401 /block.php

The problem is though, because they are not authorized to view anything on that site, block.php does not get called at all.

How do I work around this?

My httaccess looks like this:

   AuthType Basic
   AuthName "C:\\xampp\\htdocs"
   AuthUserFile C:\\xampp\\htdocs/.htpasswd
   Require valid-user

  <FilesMatch block.php>
  Order Deny,Allow

  </FilesMatch>

 ErrorDocument 401 /block.php
 ErrorDocument 400 /block.php
 ErrorDocument 403 /block.php



 ############### START BANS ###############
  • 写回答

2条回答 默认 最新

  • duandong9195 2015-03-04 21:44
    关注

    You can't use a <FilesMatch> container to grant access if you've already taken it away with your Require valid-user. What you can do is use a negative regex match so that the auth is only required when the request is NOT for /block.php:

     <FilesMatch "(?<!block\.php)$">
    
       AuthType Basic
       AuthName "C:\\xampp\\htdocs"
       AuthUserFile C:\\xampp\\htdocs/.htpasswd
       Require valid-user
    
     </FilesMatch>
    
     ErrorDocument 401 /block.php
     ErrorDocument 400 /block.php
     ErrorDocument 403 /block.php
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度