문제

can you correct & inform me please. My issue is my .htaccess hotlink protection doesn't work. I am on a shared server with .htaccess suppport. (SEO friendly linking works)

My domain type is http://www.mydomain.p.ht OR http://mydomain.p.ht

my 2 sources for my trials are:

  1. http://www.htaccesstools.com/hotlink-protection/
  2. stackoverflow

I did not forget to replace mydomain with my real domain

my .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
...
...

I also tried

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]
도움이 되었습니까?

해결책

Your methods are correct and working fine. Since your have caching enabled for these files most likely http://htaccesstools.com/test-hotlink-protection is showing you cached snapshot of the image. If you really want to test it create a html file on your localhost or some other host other than mydomain.p.ht host and include this line (replace /images/home.gif` with the path of an actual gif file):

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

And see if image shows up in browser or not. If you have Firbug network tab opened while doing this you should see Forbidden 403 status for above image.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top