View Full Version : htaccess/hotlinking for WP
NY Jester
2008-12-15, 02:36 AM
Was hoping to find an easy way to hotlink protect my blog(s) from a few domains..with the ability to add more if needed and then in turn sending that traffic to a url of my choice.
Thanks in advance.
There are two ways to do it.
1) Block everything unless you specifically allow it -- this probably doesn't play well with the nature of blogs, but, the code would be:
RewriteEngine on
# leave this line in allow empty referrers, remove to disallow empty referrers
RewriteCond %{HTTP_REFERER} !^$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(.*@)?([a-z0-9-]+\.)*yourdomain\.com(:[0-9]+)?(/.*)?$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(.*@)?([a-z0-9-]+\.)*yourseconddomain\.com(:[0-9]+)?(/.*)?$ [NC]
RewriteRule .*\.(asf|mpg|mpeg|wmv|avi|rm|gif|jpeg|jpg|png|zip)$ - [NC,F,L]
You would just add in lines with the domains you choose. A slightly faster method would be to combine the regexp lines and do something like:
RewriteEngine on
# leave this line in allow empty referrers, remove to disallow empty referrers
RewriteCond %{HTTP_REFERER} !^$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(.*@)?([a-z0-9-]+\.)*(yourdomain\.com|yourseconddomain\.com)(:[0-9]+)?(/.*)?$ [NC]
RewriteRule .*\.(asf|mpg|mpeg|wmv|avi|rm|gif|jpeg|jpg|png|zip)$ - [NC,F,L]
Alternatively, to reverse the conditions and block specific domains:
RewriteEngine on
RewriteCond %{HTTP_REFERER} hotmail|google [NC]
RewriteRule .* http://url.to/go/to.html [F,L]
Since you really don't know where your blog is going to be syndicated, you will need to watch your logs and probably use the second method.
Mr Spock
2008-12-15, 12:48 PM
Does this always work , I am getting a ton of traffic from asktiava which I want to redirect , I have this code in my htaccess:
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?sex4free.co.il/heb_htm/cat/babes.htm/.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?fode-me.com/.*$ [NC,OR]
RewriteCond %(HTTP_REFERER) ^http(s)?://(www\.)?http://www.buterbrod.com/.$[NC,OR]
RewriteCond %(HTTP_REFERER) ^http(s)?://(www\.)?http://www.superzeta.it/.$[NC,OR]
RewriteCond %(HTTP_REFERER) ^http(s)?://(www\.)?http://www.sexonabanheira.com/.$[NC,OR]
RewriteCond %(HTTP_REFERER) ^http(s)?://(www\.)?http://80.64.8.170/.$[NC,OR]
RewriteCond %(HTTP_REFERER) ^http(s)?://(www\.)?http://www.ananasik.com/.$[NC,OR]
RewriteCond %(HTTP_REFERER) ^http(s)?://(www\.)?http://www.asktiava.com/search/.$[NC,OR]
RewriteCond %(HTTP_REFERER) ^http(s)?://(www\.)?http://www.iij4u.or.jp/.$[NC,OR]
RewriteRule .* http://www.avoidhomeforeclosureblog.com [R,L]
order allow,deny
deny from 89.18.179.48
allow from all
however it doesn't seem to work any they are still getting through , what am I doing wrong |huh
NY Jester
2008-12-15, 02:39 PM
Thanks for the reply CD - so to block out one domain (at the time being) Coudl I set up htaccess like this?
RewriteEngine on
RewriteCond %{HTTP_REFERER} badsite\.com [NC]
RewriteRule .* http://url.to/go/to.html [F,L]
NY Jester
2008-12-15, 02:42 PM
Mr Spock, Im not a code guru or anything but it appears with your example, you're adding the http and the www twice? maybe remove the "http://www." from the domain string and see if that works? Perhaps only use the "asktiava.com/search/" part.
Yes NY Jester, that snippet would work for banning 1 domain.
RewriteCond %(HTTP_REFERER) ^http(s)?://(www\.)?http://www.asktiava.com/search/.$[NC,OR]
this will actually look for http://http://www.asktiava as the referrer which is probably not what you are seeing
as NY Jester says:
RewriteCond %(HTTP_REFERER) ^http(s)?://(www\.)?asktiava.com/search/[NC,OR]
I would get rid of the .$ at the end as it would force a match of 1 character -- regexp is left matched and would basically say that this needs to be anchored to the left. Same thing about the http(s)? that means that the url could be http:// or https:// the (www\.)? means that the www. is optional.
Mr Spock
2008-12-15, 07:15 PM
Yes NY Jester, that snippet would work for banning 1 domain.
RewriteCond %(HTTP_REFERER) ^http(s)?://(www\.)?http://www.asktiava.com/search/.$[NC,OR]
this will actually look for http://http://www.asktiava as the referrer which is probably not what you are seeing
as NY Jester says:
RewriteCond %(HTTP_REFERER) ^http(s)?://(www\.)?asktiava.com/search/[NC,OR]
I would get rid of the .$ at the end as it would force a match of 1 character -- regexp is left matched and would basically say that this needs to be anchored to the left. Same thing about the http(s)? that means that the url could be http:// or https:// the (www\.)? means that the www. is optional.
Changed it as you suggested , but if I click the link on asktiava.com to my site it doesn't redirect?
Are you sure your .htaccess is being parsed? what is a url on that other site that is supposed to redirect based on your rule?
can you give me the query you use from the remote site? perhaps something in the url or the way they pass it to your site is erasing the referrer.
Mr Spock
2008-12-16, 01:18 AM
This is the search query on asktiava.com:
http://www.asktiava.com/search/?p=10&n=10&t=m&m=date&q=shawna+lenee&nc=
If I click on this link to my site it doesn't redirect like it should.
http://www.myfree-porn.com/free-galleries/shawna-lenee-ibp/free.html
Here is the contents of my htaccess:
AddType php-cgi .html .htm
RewriteEngine on
RewriteCond %{HTTP:Accept-Language} (zh) [NC]
RewriteRule .* http://www.avoidhomeforeclosureblog.com [R,L]
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?sex4free.co.il/heb_htm/cat/babes.htm/.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?fode-me.com/.*$ [NC,OR]
RewriteCond %(HTTP_REFERER) ^http(s)?://(www\.)?buterbrod.com/.$[NC,OR]
RewriteCond %(HTTP_REFERER) ^http(s)?://(www\.)?superzeta.it/.$[NC,OR]
RewriteCond %(HTTP_REFERER) ^http(s)?://(www\.)?sexonabanheira.com/.$[NC,OR]
RewriteCond %(HTTP_REFERER) ^http(s)?://(www\.)?80.64.8.170/.$[NC,OR]
RewriteCond %(HTTP_REFERER) ^http(s)?://(www\.)?ananasik.com/[NC,OR]
RewriteCond %(HTTP_REFERER) ^http(s)?://(www\.)?asktiava.com/search/[NC,OR]
RewriteCond %(HTTP_REFERER) ^http(s)?://(www\.)?iij4u.or.jp/[NC,OR]
RewriteRule .* http://www.avoidhomeforeclosureblog.com [R,L]
order allow,deny
deny from 89.18.179.48
allow from all
do you have any .htaccess files down below the one in your top directory?
if so, do they contain:
RewriteOptions inherit
in them?
If they don't, they replace the existing rewrite rules
also, your rules that end with .$ won't match much of anything -- you need them to either be .*$ or remove the .$ at the end.
Mr Spock
2008-12-17, 02:15 PM
I changed the htaccess using the coding you gave Nyjester as follows
RewriteEngine on
RewriteCond %{HTTP_REFERER} asktiava.com [NC]
RewriteRule .* http://avoidhomeforeclosureblog.com [F,L]
When I click on the link on asktiava.com it gives a 403 error |thumb
What do I need to change to direct it to http://avoidhomeforeclosureblog.com
vBulletin® v3.8.1, Copyright ©2000-2026, Jelsoft Enterprises Ltd.