【问题标题】:htaccess error pages and authenticationhtaccess 错误页面和身份验证
【发布时间】:2024-05-29 16:20:01
【问题描述】:

任务 1:我正在使用 htaccess Options -Indexes 来停止目录列表。但是,我希望它显示 404 page not found 响应而不是 403 禁止响应。我怎样才能为每个目录做到这一点?

任务 2:假设我有一个包含一些可下载文件的目录。有没有办法阻止用户使用 .htaccess 下载文件,直到他们登录到我的网站?

【问题讨论】:

    标签: php .htaccess authentication


    【解决方案1】:

    任务 1:试试这个

    RewriteEngine On
    RewriteBase   /my_directory
    RewriteRule   ^$ - [R=404,L]
    

    任务 2:首先您需要防止使用 htaccess 直接下载文件。
    然后你必须创建你的 php 文件来检查是否登录。
    如果登录,则将 header 设置为目标文件,然后打开它。

    这 2 个教程将为您提供指导。
    http://www.ssdtutorials.com/tutorials/title/download-file-with-php.html
    http://www.devshed.com/c/a/PHP/Simple-and-Secure-PHP-Download-Script-with-Limits-Tutorial/

    【讨论】: