: IP, and page-specific redirect? I'm trying to send a particular IP, that is trying to get one page on my site, to another page, and do this through my .htaccess file. I've seen many general
I'm trying to send a particular IP, that is trying to get one page on my site, to another page, and do this through my .htaccess file. I've seen many general descriptions of how to do it (in many syntactically different ways) but frankly none of them work. I put these command
s, of the sort
RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^99.888.777.66$
RewriteRule ^/askedforpage.html /redirecttopage.html [R,NE,NC]
in my .htaccess file ... but these commands simply leave my site non-functional. I'm using Apache 2.2, on a Mac with OS 10.6.8.
How do I do this??
Here is my .htaccess file, without the "deny" commands for malicious IPs.
Header set Accept-Ranges none
order allow,deny
allow from all
Redirect permanent xyz.html xxyyzz.com/header.htm
More posts by @Kaufman445
2 Comments
Sorted by latest first Latest Oldest Best
This is just to report that the advice of w3d was exactly right. The way you do this is
RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^99.888.777.66$
RewriteRule ^askedforpage.html /redirecttopage.html [R,NC,L]
(I already had FollowSymLinks on, and mod_rewrite enabled.) The "L" (LAST) flag is important!
These .htaccess commands look for a request by IP 99.888.777.66 (and only that IP) for the page "askedforpage.html", and return the page "redirecttopage.html" instead. Unless otherwise denied, that IP can get anything else.
Tip 'o the bowler to w3d.
There's not really very much wrong with the code you have posted. There are certainly no errors in your code that should leave your site non-functional. As it stands it is syntactically valid. However, check your line endings to make sure you have no spurious characters - this can cause problems.
Try the following:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^99.888.777.66$
RewriteRule ^askedforpage.html /redirecttopage.html [R,NC,L]
I have removed the / (slash) prefix in the RewriteRule pattern. The directory prefix is removed in per-directory .htaccess files before the pattern is matched (so URL patterns never start with a slash). I have also removed the NE flag - this is unnecessary in the code you have posted (although is not an error).
EDIT: I've added the L (LAST) flag, although to be honest it shouldn't make much of a difference in this case, providing there are no conflicting rules in your (or another) .htaccess file - which there don't appear to be from your question.
It is admittedly more usual to specify the L flag in RewriteRule external redirects since generally you do not want the rewrite engine to reprocess your rules after you have established the redirect.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.