首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >防热连接与.htaccess

防热连接与.htaccess
EN

Stack Overflow用户
提问于 2022-07-02 06:01:38
回答 1查看 33关注 0票数 0

Hotlink Protection not working with .htaccess中,讨论了通过.htaccess指令防止热链接的问题,但是其中的答案并没有为我的问题提供一个解决方案。

这是我的问题:

https://janis-joplin.servidor-alicante.com/中,我有以下.htaccess:

代码语言:javascript
复制
DirectoryIndex index.php index.html index.htm
Options -Indexes

RewriteEngine On

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://janis-joplin.servidor-alicante.com [NC]
RewriteCond %{HTTP_REFERER} !^https://janis-joplin.servidor-alicante.com [NC]
RewriteCond %{HTTP_REFERER} !^https://(www\.)?google.com [NC]
RewriteCond %{HTTP_REFERER} !^https://(www\.)?facebook.com [NC]
RewriteCond %{HTTP_REFERER} !^https://(www\.)?twitter.com [NC]
RewriteRule \.(gif|jpg|jpeg|bmp|zip|rar|mp3|flv|swf|xml|php|png|css|pdf)$ https://janis-joplin.servidor-alicante.com/_res/janis.jpg [NC,R,L]

RewriteRule ^ads.txt$ ads_tm.php [L]

RewriteRule ^janis-joplin/(.*) /$1 [L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) - [PT,L]
RewriteRule ^(.+) index.php?url=$1

https://jimi-hendrix.servidor-alicante.com/_dev/test.htm中,我有:

代码语言:javascript
复制
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>test</title>
</head>

<body>
<img src="http://janis-joplin.servidor-alicante.com/_photos/wolman.gif">
<img src="https://janis-joplin.servidor-alicante.com/_photos/wolman.gif">
</body>
</html>

但是在jimi子域中,我可以看到joplin子域中的图像。

我做错了什么?提亚

EN

回答 1

Stack Overflow用户

发布于 2022-07-02 15:46:52

您需要检查网络流量- HTTP请求头(在浏览器开发工具中可以这样做).是否在对这些图像的请求中发送Referer头?Referer标头设置为什么?

RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://janis-joplin.servidor-alicante.com RewriteCond %{HTTP_REFERER} !^https://janis-joplin.servidor-alicante.com NC

Referer头将不会在第一个图像请求中发送(默认情况下),因为您正在从HTTPS (安全)页面发出HTTP (不安全)请求。默认浏览器行为会在此实例中取消Referer标头。在“热链接”规则块中显式地允许一个空的Referer头(上面的第一个条件),这样您就可以期望显示第一个图像。(实际上,您确实需要允许一个空的Referer头。)

不清楚为什么显示第二个映像(假设您的.htaccess指令正在处理)而不查看HTTP请求头(并且知道在引用页面上设置了什么headers )。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72836828

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档