使用.htaccess阻止Pdf文件直接访问 [英] Blocking Pdf Files From Direct Access Using .htaccess

查看:207
本文介绍了使用.htaccess阻止Pdf文件直接访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题已经问了好几次了,我尝试了所有可用的选项,但是我仍然很难阻止使用绝对URL直接访问pdf文件。

This question have been on SO quite a few times, i have tried all the available options but still i am having hard time blocking a pdf file from direct access using absolute URL.

我在.htaccess文件中使用以下代码,该文件位于pdf所在的同一文件夹中

I using the following code inside .htaccess file which is in the same folder where pdf's are

Order Allow,Deny
  <FilesMatch "^[^.]+\.(gif|jpe?g|png|pdf|doc|docx|txt|rtf|ppt|pptx|xls|mp4|mov|mp3|mpg|mpeg)$">
   Deny from all
  </FilesMatch>

当我访问pdf文件目录时,它显示403禁止访问,但当我进入pdf的绝对URL,它将开始在浏览器中呈现pdf。

When i access the directory of the pdf files it shows me a 403 forbidden access but the moment i enter the absolute url of the pdf it starts rendering the pdf in the browser.

Directory Url http://thetutlage.com/demo/pdfReader/files

Directory Url http://thetutlage.com/demo/pdfReader/files

Pdf Url:- http://thetutlage.com/demo/pdfReader/files/tracemonkey.pdf

Pdf Url :- http://thetutlage.com/demo/pdfReader/files/tracemonkey.pdf

任何帮助都会很棒。如果文件扩展名为.pdf,但我似乎也尝试过使用重定向规则,但这似乎也不起作用。

Any help will be great. I have also tried using a redirect rule if a file has .pdf extension but that doesn't seems to be working as well.

推荐答案

工作正常:

Order Allow,Deny
Allow from all
<Files ~ "\.(gif|jpg|png|pdf)$">
Deny from all
</Files>

这篇关于使用.htaccess阻止Pdf文件直接访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆