Deny access and silently redirect

Fix it!!

Deny access and silently redirect

Postby Jangla » Thu Jun 12, 2008 12:18 am

I need to be able to deny access to an entire site for a single ip address (possibly a couple more later but one for now).

Rather than use Allow, Deny, I'd rather use a redirect in which the URL doesn't change. Largely because I want to redirect the offending pip address to a php page that will add a cookie to the offending machine to track if they change their ip address so I can update the htaccess to deny them access again.

Anyone able to help?

I've tried a number of examples I've found online and so far managed to create nothing but 500 errors and infinte loops! Oh yea, and I managed to block all ip addresses at one point :o

Edit: Should also point out there's a bunch of other stuff already in my htaccess file that needs to remain working.
Jangla
 
Posts: 7
Joined: Fri Dec 07, 2007 6:19 am

Postby Jangla » Thu Jun 12, 2008 1:31 am

More info: I've managed to block the ip but there's a risk they could change their ip.

So now I need to work out how to use htaccess to read a cookie on their machine and redirect again.

Anyone?
Jangla
 
Posts: 7
Joined: Fri Dec 07, 2007 6:19 am

Postby richardk » Fri Jun 13, 2008 2:17 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Is it a bad IP address.
RewriteCond %{REMOTE_ADDR}  ^1\.2\.3\.4$ [OR]
# Or another bad IP address.
RewriteCond %{REMOTE_ADDR}  ^5\.6\.7\.8$ [OR]
# Or do they have the cookie set?
RewriteCond %{HTTP_COOKIE} ^(.*;\ )?cookiename=cookievalue(;\ .*)?$
# Rewrite to one file to do whatever you want.
RewriteRule ^bad_ips\.php$ /bad_ips\.php [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Security with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 6 guests

cron