2

你能纠正并通知我吗?我的问题是我的 .htaccess 热链接保护不起作用。我在具有 .htaccess 支持的共享服务器上。(SEO 友好链接有效)

我的域类型是http://www.mydomain.p.ht或者http://mydomain.p.ht

我的 2 个试验来源是:

  1. http://www.htaccesstools.com/hotlink-protection/
  2. 堆栈溢出

我没有忘记mydomain用我的真实域名替换

我的 .htaccess

RewriteEngine On
RewriteBase /

# hotlink protection
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mydomain.p.ht [NC]
RewriteRule \.(jpg|jpeg|png|gif|css)$ - [NC,F,L]

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

# File caching is another famous approach in optimizing website loading time
<FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf|js|css|pdf)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>

#SEO friendly linking
...
...

我也试过

1

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mydomain.p.ht [NC]
RewriteRule \.(flv)$ - [NC,F,L]

2

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mydomain\.p\.ht/.*$ [NC]
RewriteRule .*\.(jpg|jpeg|png|gif)$ - [F,NC,L]
4

1 回答 1

1

你的方法是正确的并且工作正常。由于您为这些文件启用了缓存,因此很可能http://htaccesstools.com/test-hotlink-protection会向您显示图像的缓存快照。如果您真的想测试它,请在您的 localhost 或主机以外的其他主机上创建一个 html 文件,mydomain.p.ht并包含此行(将 /images/home.gif` 替换为实际 gif 文件的路径):

<img border="0" src="http://mydomain.p.ht/images/home.gif">

并查看图像是否显示在浏览器中。如果您在执行此操作时打开了 Firbug 网络选项卡,您应该会看到上图的 Forbidden 403 状态。

于 2013-04-02T13:26:25.283 回答