【问题标题】:Apache: restrict access to specific subdirectory, based on referer?Apache:根据referer限制对特定子目录的访问?
【发布时间】:2020-11-03 21:01:00
【问题描述】:

我只想允许来自特定站点的访问者访问某些文件夹,否则使用 Apache 重定向或限制流量。

在这些示例(不起作用)中,我们的想法是只允许来自“validreferersite.com”的访问者访问 /test/ 子目录。我一直在尝试这些但没有成功:

<Location /test/>
<If "%{HTTP_HOST} != 'validreferersite.com'">
Redirect / http://www.anothersite.com/
</If>
</Location>

这都不是(在我的受限文件夹上使用 .htaccess):

RewriteCond %{HTTP_REFERER} !^http://(www\.)?validreferersite\.com/ [NC]
RewriteRule (^|/)test(/|$) - [F,NC]

--

仅供参考,目前我在基于 Nginx 的服务器上使用它(没有重定向,只有 403)。

我需要 Apache 的等价物:

location /test/ {       
 valid_referers blocked server_names validreferersite.com *.validreferersite.com 
             if ($invalid_referer) {
     return   403;
            }

【问题讨论】:

    标签: apache


    【解决方案1】:

    自己的答案:没有找到确切的解决方案,但作为一种解决方法,您可以在要“保护”的文件夹上使用 .htaccess。

    下面的代码将保护当前文件夹中的所有 .html 文件免受所有非来自 validreferersite.com 的访问者的影响

    RewriteEngine On
    RewriteCond %{HTTP_REFERER} !^https://validreferersite.com
    RewriteRule \.html$ - [L,F]
    

    【讨论】:

      猜你喜欢
      • 2011-06-18
      • 2020-03-15
      • 2021-12-24
      • 2019-01-05
      • 2018-11-12
      • 1970-01-01
      • 1970-01-01
      • 2012-09-18
      • 1970-01-01
      相关资源
      最近更新 更多