homepage Welcome to WebmasterWorld Guest from 54.167.138.53
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Is there any way to block a referrer?
underwatercolours




msg:1512308
 9:13 pm on Aug 2, 2005 (gmt 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.

 

jatar_k




msg:1512309
 9:26 pm on Aug 2, 2005 (gmt 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.

underwatercolours




msg:1512310
 9:38 pm on Aug 2, 2005 (gmt 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.

jatar_k




msg:1512311
 12:15 am on Aug 3, 2005 (gmt 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 ;)

jdMorgan




msg:1512312
 12:43 am on Aug 3, 2005 (gmt 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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved