【问题标题】:Block main domain and sub domains direct file access with single .htaccess使用单个 .htaccess 阻止主域和子域直接文件访问
【发布时间】:2019-05-26 08:02:21
【问题描述】:

我想保护对我的服务器的直接文件访问。我有以下代码,它运行良好:

#To protect direct access

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?maindomain.com [NC]
RewriteRule \.(xls|pdf|doc|docx|ppt|pptx)$ - [NC,F,L]

我想保护 test.maindomain.com、blog.maindomain.com 等子域, 1)我怎么能用上面的代码做到这一点? 2)我需要把这段代码放在每个子域中吗?

【问题讨论】:

    标签: php laravel amazon-web-services .htaccess server


    【解决方案1】:

    您可以尝试使用此规则来屏蔽这两个域:

    RewriteEngine on
    
    RewriteCond %{HTTP_REFERER} !https?://(www\.|test\.|blog\.)?maindomain\.com [NC]
    RewriteRule \.(?:xls|pdf|doc|docx|ppt|pptx)$ - [NC,F,L]
    

    【讨论】:

    • 如果我在 .com 之后删除 ` before .com and $`,它就可以工作
    • 哦,是的,这是正确的,因为 HTTP_REFERER 是更长的 URI,现在已修复。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2012-11-18
    • 1970-01-01
    • 2011-12-01
    • 2022-11-26
    • 2014-07-21
    • 2012-11-03
    • 1970-01-01
    • 2015-10-07
    相关资源
    最近更新 更多