Am I Famous Now…

...I Am So Coordinated

HOWTO : htaccess IP Redirect To Any Site

April 9th, 2007 by WebMatrix · 5 Made Me Smarter

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.

Tags: , , , , // 4,119 Views

5 have made me smarter ↓

  1. Gravatar

    1 Jinge // Jun 4, 2007 at 8:12 pm// View all comments by Jinge//  Add karma Subtract karma  +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. Gravatar

    2 Franky // Jun 4, 2007 at 8:40 pm// View all comments by Franky//  Add karma Subtract karma  +0

    Try with a [space] (empty) in between the URL and [R,L]. And also a space after RewriteCond and RewriteRule

  3. Gravatar

    3 Franky // Jun 4, 2007 at 8:43 pm// View all comments by Franky//  Add karma Subtract karma  +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. Gravatar

    4 Tom // Jul 17, 2007 at 8:35 am// View all comments by Tom//  Add karma Subtract karma  +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. Gravatar

    5 jonathon // Jan 21, 2008 at 2:45 pm// View all comments by jonathon//  Add karma Subtract karma  +0

    thanks, just what i been looking for to redirect nightmare spammers, away from my blog and forums.

Comment Policy

Spam comments are not supported and will be deleted.

This site supports a dofollow policy for comments, accordingly I do reserve the right to remove your URL if your comment seems to be nothing more than a plug to your site. This is a non-discutable decision from my side.

Stay polite and ad rem in the comments. We all, me too, have had our child days, but have grown up. Flame comments will be deleted.
If you really want to flame, feel free and do it on your own blog. Feel free to link back.

Off topic comments will be deleted.