Most of us who want to keep a user out of their site use the Cpanel IP block tool. I am a dork and prefer to learn stalkers something, so I love to fiddle myself with my htaccess file. The code to redirect a specific IP to an interesting site about cyberstalking is simple.
Add the following code to your htaccess file (of course don’t forget to use the IP you want to redirect).
Redirect Single IP To Any Site With htaccess
RewriteCond %{REMOTE_ADDR} ^64\.126\.81\.30$
RewriteRule .* http://www.usdoj.gov/criminal/cybercrime/cyberstalking.htm [R,L]
If you want to redirect more IP, just add them in a new line, right under the first IP, but you’ll have to add [OR] at the end of every line with an IP. Except at the last line!.
Redirect Several IPs To Any Site With htaccess
RewriteCond %{REMOTE_ADDR} ^64\.126\.81\.30$ [OR]
RewriteCond %{REMOTE_ADDR} ^75\.117\.244\.27$
RewriteRule .* http://www.usdoj.gov/criminal/cybercrime/cyberstalking.htm [R,L]
It’s as simple as that, and much more fun to be informative than just ban someone IMNSHO.
Note that [R,L] belongs on the same line as the URL you want to use.
5 have made me smarter ↓
1 Jinge // Jun 4, 2007 at 8:12 pm// View all comments by Jinge//
+0
I can’t make it work..
Let’s say I want to redirect only 200.200.200.200 to my http://bilderblogg.se
RewriteCond %{REMOTE_ADDR} ^200\.200\.200\.200$
RewriteRule .* http://bilderblogg.se/index.php[R,L]
Only that to lines in my .htaccess and nothing happens when I test it.
Yes, I change 200.200 etc to my own ip-number…
What did I do wrong?
Rgds Jinge
2 Franky // Jun 4, 2007 at 8:40 pm// View all comments by Franky//
+0
Try with a [space] (empty) in between the URL and [R,L]. And also a space after RewriteCond and RewriteRule
3 Franky // Jun 4, 2007 at 8:43 pm// View all comments by Franky//
+0
But be aware, when you do that to your own IP, I recommend you to proxy to your site, because the results might be funny.
4 Tom // Jul 17, 2007 at 8:35 am// View all comments by Tom//
+0
Is it possible to redirect ANYONE who doesn’t belong to a set of IPs? kind of the opposite of what you’ve done here. I want to redirect everyone who doesn’t belong to a particular subnet.
Cheers
5 jonathon // Jan 21, 2008 at 2:45 pm// View all comments by jonathon//
+0
thanks, just what i been looking for to redirect nightmare spammers, away from my blog and forums.