Greenguy's Board

Greenguy's Board (http://www.greenguysboard.com/board/index.php)
-   Blogs and Blogging (http://www.greenguysboard.com/board/forumdisplay.php?f=8)
-   -   htaccess/hotlinking for WP (http://www.greenguysboard.com/board/showthread.php?t=50535)

NY Jester 2008-12-15 01:36 AM

htaccess/hotlinking for WP
 
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.

cd34 2008-12-15 03:24 AM

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:

Code:

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:

Code:

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:

Code:

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 11:48 AM

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:

Code:

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 01:39 PM

Thanks for the reply CD - so to block out one domain (at the time being) Coudl I set up htaccess like this?
Code:

RewriteEngine on

RewriteCond %{HTTP_REFERER} badsite\.com [NC]
RewriteRule .* http://url.to/go/to.html [F,L]


NY Jester 2008-12-15 01: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.

cd34 2008-12-15 02:11 PM

Yes NY Jester, that snippet would work for banning 1 domain.

Code:

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:

Code:

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 06:15 PM

Quote:

Originally Posted by cd34 (Post 432868)
Yes NY Jester, that snippet would work for banning 1 domain.

Code:

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:

Code:

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?

cd34 2008-12-15 08:51 PM

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 12:18 AM

This is the search query on asktiava.com:

http://www.asktiava.com/search/?p=10...awna+lenee&nc=


If I click on this link to my site it doesn't redirect like it should.

http://www.myfree-porn.com/free-gall...-ibp/free.html

Here is the contents of my htaccess:

Code:

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


cd34 2008-12-16 12:47 AM

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 01:15 PM

I changed the htaccess using the coding you gave Nyjester as follows

Code:

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


All times are GMT -4. The time now is 06:45 PM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc