Send single IP address to a specific page using mod_rewrite

Apache on our CentOS VDS is being monitored by the hosting company (due to previous issues when on a shared hosting server). The site they are monitoring is an on-line store and this has the rather unfortunate side effect of making it appear as if there are numerous visitors on-line at any given moment. It also fills the store's logs with irrelevant entries. None of this is critical but I'd like to eliminate these issues.

I am trying to use mod_rewrite commands in the .htaccess file to redirect that one IP address to a dummy page rather than letting it enter the store. Googling produces many examples but they are all for requests for a specific page, whereas in my case no page is being requested.

Here is what I've ended up with (192.168.0.23 being my test client) but it just results in a loop:

RewriteCond %{REMOTE_HOST} 192\.168\.0\.23
RewriteRule .* /monitor.html [R=301,L]

This example is being tested on my dev server using wget (using either the IP address or the domain name) and results in this:

H:\>wget http://192.168.0.18
--2011-09-26 09:01:07--  http://192.168.0.18/monitor.html
Connecting to 192.168.0.18:80... connected.

the response is repeated until

--2011-09-26 09:01:07--  http://192.168.0.18/monitor.html
Connecting to 192.168.0.18:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://192.168.0.18/monitor.html [following]
20 redirections exceeded.

Is what I'm trying to do possible using mod_rewrite or should I tackle this some other way?

tl;dr:

  • I need to redirect any request from a specific IP address to a dummy page
  • The response must come from the web server, as that is what is being monitored

Edit

Here is the content of rewrite_log after performing another wget http://192.168.0.18

192.168.0.23 - - [21/Sep/2011:21:27:07 +1000] [192.168.0.18/sid#937eab8][rid#95330f8/initial] (2) [perdir /path/to/website/files/] explicitly forcing redirect with http://192.168.0.18/monitor.html
192.168.0.23 - - [21/Sep/2011:21:27:07 +1000] [192.168.0.18/sid#937eab8][rid#95330f8/initial] (1) [perdir /path/to/website/files/] escaping http://192.168.0.18/monitor.html for redirect
192.168.0.23 - - [21/Sep/2011:21:27:07 +1000] [192.168.0.18/sid#937eab8][rid#95330f8/initial] (1) [perdir /path/to/website/files/] redirect to http://192.168.0.18/monitor.html [REDIRECT/301]
192.168.0.23 - - [21/Sep/2011:21:27:07 +1000] [192.168.0.18/sid#937eab8][rid#9535100/initial] (3) [perdir /path/to/website/files/] strip per-dir prefix: /path/to/website/files/monitor.html -> monitor.html
192.168.0.23 - - [21/Sep/2011:21:27:07 +1000] [192.168.0.18/sid#937eab8][rid#9535100/initial] (3) [perdir /path/to/website/files/] applying pattern '^/monitor\.html$' to uri 'monitor.html'
192.168.0.23 - - [21/Sep/2011:21:27:07 +1000] [192.168.0.18/sid#937eab8][rid#9535100/initial] (4) [perdir /path/to/website/files/] RewriteCond: input='192.168.0.23' pattern='192\.168\.0\.23' => matched
192.168.0.23 - - [21/Sep/2011:21:27:07 +1000] [192.168.0.18/sid#937eab8][rid#9535100/initial] (2) [perdir /path/to/website/files/] rewrite 'monitor.html' -> '/monitor.html'
192.168.0.23 - - [21/Sep/2011:21:27:07 +1000] [192.168.0.18/sid#937eab8][rid#9535100/initial] (2) [perdir /path/to/website/files/] explicitly forcing redirect with http://192.168.0.18/monitor.html
192.168.0.23 - - [21/Sep/2011:21:27:07 +1000] [192.168.0.18/sid#937eab8][rid#9535100/initial] (1) [perdir /path/to/website/files/] escaping http://192.168.0.18/monitor.html for redirect
192.168.0.23 - - [21/Sep/2011:21:27:07 +1000] [192.168.0.18/sid#937eab8][rid#9535100/initial] (1) [perdir /path/to/website/files/] redirect to http://192.168.0.18/monitor.html [REDIRECT/301]

Hopfuly someone can make sense of it. As far as I can tell it thinks monitor.html <> monitor.html.


Solution 1:

RewriteEngine On
RewriteCond %{REMOTE_ADDR} 192\.168\.0\.23
RewriteCond %{REQUEST_URI} !/monitor\.html$
RewriteRule $ /monitor.html [R=301,L]

~

Solution 2:

Just don't redirect when the requested page is the monitoring page:

RewriteCond %{REMOTE_HOST} ^192\.168\.0\.23$
RewriteRule !^monitor\.html$ /monitor.html [R=301,L]

(edited for .htaccess context and exact host IP matching)