【问题标题】:deny direct access to a files but allow php and html to read it from .htaccess拒绝直接访问文件,但允许 php 和 html 从 .htaccess 读取它
【发布时间】:2012-06-04 15:42:19
【问题描述】:

我需要知道如何拒绝访问图像文件夹,但只允许从 php/html 读取它。

我认为最好的方法是在该文件夹中使用 .htaccess,例如

deny from all
Options -indexes
AddHandler cgi-script .php .htm .html .sh
Options -ExecCGI

但这不起作用,因为我必须在根文件夹 .htaccess 以下

<FilesMatch "\.(gif|jpe?g|doc?x|pdf|zip|png)$">
AddHandler cgi-script .php .htm .html .sh
Allow from all
</FilesMatch>
<Files 403.shtml>
order allow,deny
allow from all
</Files>

解决方案

RewriteCond %{HTTP_HOST} ^xxx.com$
RewriteRule ^/?$ "http\:\/\/www\.xxx\.com\/index\.php" [R=301,L] 
RewriteCond %{HTTP_REFERER} !^http://(www\.)?xxx\.com/.*$ [NC]
RewriteRule _files/photo/([^/]+)\.(gif|png|jpg)$ - [F] 

也没有工作...?有专家吗?

【问题讨论】:

    标签: apache .htaccess


    【解决方案1】:

    用这个替换你现有的代码:

    RewriteCond %{HTTP_HOST} ^xxx\.com$
    RewriteRule ^$ http://www.xxx.com/index.php [R=301,L] 
    
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?xxx\.com/ [NC] 
    RewriteRule ^_files/photo/[^.]+\.(jpe?g|gif|bmp|png)$ - [F,NC]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-27
      • 2016-03-23
      • 2013-05-14
      • 2017-10-22
      • 2014-12-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多