http://www.mydomain.p.ht
或http://mydomain.p.ht
我没有忘记用我的真实域名替换mydomain
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
...
...
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mydomain.p.ht [NC]
RewriteRule \.(flv)$ - [NC,F,L]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mydomain\.p\.ht/.*$ [NC]
RewriteRule .*\.(jpg|jpeg|png|gif)$ - [F,NC,L]
答案 0 :(得分:1)
您的方法正确且工作正常。由于您已为这些文件启用了缓存,因此http://htaccesstools.com/test-hotlink-protection
很可能会向您显示图像的缓存快照。如果你真的想测试它在你的localhost或mydomain.p.ht
主机以外的其他主机上创建一个html文件并包含这一行(用实际的gif文件的路径替换/ images / home.gif`): / p>
<img border="0" src="http://mydomain.p.ht/images/home.gif">
查看图片是否显示在浏览器中。如果您在执行此操作时打开了Firbug网络选项卡,则应该看到上面图像的Forbidden 403状态。