douyu1990 2018-05-19 00:17
浏览 42
已采纳

如果直接定位,则限制对文件的访问

I have a basic folder structure like this:

index.php
assets/
  docs/
    document.pdf
includes/
  script.php

I need to be able to block access to the document if someone was to try and get it directly, for example: www.domain.com/assets/docs/document.pdf but allow access if was to be linked from the index.php page.

Would there be a way I can block access like this, or, is there a method of embedding the pdf on the page? I'm open to using PHP or jQuery if it can be done through that as well.

Some of the methods I have tried have been including deny restrictions in the htaccess but then that obviously blocks it altogether.

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dongshuo1856 2018-05-19 00:45
    关注

    You can use the Referer header directly in your Apache configuration (an assets/docs/.htaccess file will do):

    SetEnvIf Referer "domain\.com" is_local_referer
    <FilesMatch "\.pdf$">
        Require env is_local_referer
    </FilesMatch>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了