Forum Moderators: phranque

Message Too Old, No Replies

Rewrite Cond Remote Host

         

JimmieT

1:38 pm on Feb 28, 2011 (gmt 0)

10+ Year Member



After reviewing my site logs for over 6 months, it appears that my htaccess file does not work for some things. I've searched this site, but still don't have a clue. Here is my section that I think is faulty.

RewriteEngine on
Options +FollowSymLinks
RewriteBase /
RewriteCond %{REMOTE_HOST} \.xx [NC,OR]
RewriteCond %{REMOTE_HOST} \.yy [NC,OR]
RewriteCond %{REMOTE_HOST} \.zz [NC]
RewriteCond %{REQUEST_URI} !(robots\.txt|/error/forbidden\.html)
RewriteRule ^(.*)$ - [F]

I also seem to have the same problem using %{HTTP_REFERER}

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_REFERER} #*$!\.net [NC,OR]
RewriteCond %{HTTP_REFERER} #*$!xx\.com [NC,OR]
RewriteCond %{HTTP_REFERER} \#*$!xx\.gov [NC]
RewriteCond %{REQUEST_URI} !(robots\.txt|/error/forbidden\.html)
RewriteRule ^(.*)$ - [F]

Jim

jdMorgan

5:14 pm on Mar 8, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Using the REMOTE_HOST variable invokes a DNS lookup -- a request going *out* of your server to the DNS system. So, this is quite inefficient, and a lot of hosts disable that function. That's probably why it doesn't work for you. I'd recommend asking your host about this.

As for %{HTTP_REFERER}, that should work on any normally-configured Apache server. I don't see any important problems with your second rule, so really, it should be working and returning a 403-Forbidden response to any request with the specified referrers unless those requests are for robots.txt or for your custom 403 error page.

Jim