Recently, a reader named Alison left a comment requesting help with a particular htaccess trick. She wanted to know how to permanently redirect (301) all requests for a specific page when requested from a specific IP address. In other words, when a visitor coming from 123.456.789 requests the page requested-page.html, the visitor will be redirected to just-for-you.html. All visitors not coming from that specific IP address are not redirected, and thus will see the originally requested page. Further, the redirect must apply only to requested-page.html, such that every visitor — including the one coming from 123.456.789 — will be able to see all of the other pages. Here is the htaccess code to make it happen:

To use this redirect, simply edit the IP address, requested page, and redirect page. Copy and paste the code into your htaccess file and upload to your server. Test the 301 redirect via proxy and that’s it. Relax and enjoy!

Man, today is just not my day!
Anyway, you are absolutely correct..
I meant 301, said 301, and have no idea why I wrote 302 in the code (could be all the pain meds?).. either way, thank you for catching the error. The code now reads correctly (i think)..

I wasn’t thinking about it until people start to ask how to do it for specific IPs, Can probably use this to send SE ip to a page and regular ip to another page, maybe further divide the regular ip into region for geo targetted cloaking.

Thank you for the kind remarks, Lisa :) And, no, you do not need to rewrite the first two directives for each different IP that you would like to block. For example, this will work just fine for multiple IPs:

how about redirecting for a specific ISP. im trying to give a certain annoying character on my site a message, he uses a certain ISP that none of my other uses use. In my log files he shows up as
##-###-##-###.dhcp.insightbb.com

His ip is constantly changing and im talking about every octet, not just the last 2.

Books

Links

About the site

Perishable Press is the work of Jeff Starr, professional developer, designer, author, and publisher with over 10 years of experience. Check out some of Jeff's books and projects, follow on Twitter, or learn more »

Fun fact: Perishable Press has been online since 2005, and now features over 700 articles and more than 11,000 comments. More stats »