防止热链接在我的网站上不起作用?

时间:2019-11-21 16:47:38

标签: .htaccess hotlinking

我已经尝试了Web和此站点上建议的许多解决方案,但是防止热链接的功能似乎在我的站点上无效。

我对htaccess的规则知之甚少。

我有这个.htaccess

Options -Indexes

php_value date.timezone 'Europe/Rome'

RewriteEngine On
RewriteBase /

<FilesMatch "\.user\.ini|info\.php|error_log">
Order Allow,Deny
Deny from all
</FilesMatch>

RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://mysubdomain.mysite.com/$1 [R,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule [./]* index.php [L]

我在该文件的末尾插入了http://altlab.com/htaccess_tutorial.html中建议的代码:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ https://other_img_url [L]

然后我在以下页面中测试了图像URL(例如https://mysubdomain.mysite.com/img/mylogo.png):http://altlab.com/hotlinkchecker.php,但是该图像始终显示,因此热链接保护不起作用。

我还尝试仅在.htaccess中插入这些行,不能插入空行,但是仍然无法正常工作:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ https://other_img_url [L]

我将文件.htaccess放在了许多目录中:

root/
   .htaccess
   public_html/
       .htaccess
       img/
   mysubdomain/
       public_html/
           .htaccess
           img/
               mylogo.png

该站点正常运行,因此.htaccess文件中没有语法错误。

我的网站位于共享托管中,因此我无法直接访问服务器,也无法从命令行运行一些批处理命令(我也尝试了托管提供程序建议的代码,但未成功)。

我做错了什么?

我错过了什么?

服务器端是否有任何干扰的东西?

非常感谢!

0 个答案:

没有答案