Welcome to WebmasterWorld Guest from 54.166.148.252

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Is there any way to block a referrer?

     
9:13 pm on Aug 2, 2005 (gmt 0)

New User

10+ Year Member

joined:June 19, 2005
posts:2
votes: 0


I have a number of web sites that link to my site. They are mostly unrelated blogs and forums linking to pages and graphics on my server. Is there any way to block them? I have been able to block specific IP addresses, but I'd like to block the whole site if that is possible.
9:26 pm on Aug 2, 2005 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 0


Welcome to WebmasterWorld underwatercolours,

Do you do any scripting?

you could try something like this for images
protecting images with php and .htaccess [webmasterworld.com]

You could also redirect or ban based on the HTTP_REFERER using php as well. You can do these in other languages too, php just happens to be my weapon of choice.

9:38 pm on Aug 2, 2005 (gmt 0)

New User

10+ Year Member

joined:June 19, 2005
posts:2
votes: 0


I've done a few things with the .htaccess file but don't know the proper syntax. I found this on another post:

RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://(www\.)?offendersite.net/.*$
RewriteCond %{REQUEST_URI} ^/.*$
RewriteRule ^.* - [F]

It appears to be working so far for links to pages, but not to images and movies.

12:15 am on Aug 3, 2005 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 0


I have to admit I am no rewrite master but I moved this to Apache so that maybe one of the masters there can help

this will also serve as a shameless bump ;)

12:43 am on Aug 3, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Flush your browser cache before testing *any* change to your access-control code. Otherwise, the browser will simply return its cached copy of whatever you request, the request won't be sent to your server, and your server-side code can't have any effect.

The code you posted can be simplified and made more efficient by eliminating redundant regex and directives:


RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://(www\.)?offendersite\.net
RewriteRule .* - [F]

If you use a custom 403 error page, it will need to be excluded from the rewrite, otherwise, you'll get an 'infinite' rewrite loop:

RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://(www\.)?offendersite\.net
RewriteCond %{REQUEST_URI} !^/path_to_your_custom_403_page\.html$
RewriteRule .* - [F]

Jim