Permanently Redirect a Specific IP Request for a Single Page via htaccess
Post #374 categorized as Function, last updated on Nov 5, 2007
Tagged with apache, htaccess, mod_rewrite, redirect, tips, tricks
Not the most interesting title, but “oh well”..
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:
# permanently redirect specific IP request for single page
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} 123\.456\.789
RewriteCond %{REQUEST_URI} /requested-page\.html$
RewriteRule .* /just-for-you.html [R=301,L]
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!
Share this..
Related articles
- 1-Minute Tutorial: Permanent (301) Redirect via PHP or htaccess
- Redirect All (Broken) Links from any Domain via HTAccess
- htaccess Combo Pack: WordPress Permalinks and non-www Redirect
- Redirect WordPress Feeds to Feedburner via htaccess (Redux)
- WordPress Feedburner HTAccess Redirect for Default (Non-Permalink) Feed URLs
- Redirect WordPress Individual Category Feeds to Feedburner via HTAccess
- Redirect All Requests for a Nonexistent File to the Actual File
#1 — tim
Shouldn’t that last line be:
RewriteRule .* /just-for-you.html [R=301,L]
302 is a temporary re-direct. 301 is permanent.