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 ( 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:

--2011-09-26 09:01:07--
Connecting to connected.

the response is repeated until

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

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


  • 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


Here is the content of rewrite_log after performing another wget - - [21/Sep/2011:21:27:07 +1000] [][rid#95330f8/initial] (2) [perdir /path/to/website/files/] explicitly forcing redirect with - - [21/Sep/2011:21:27:07 +1000] [][rid#95330f8/initial] (1) [perdir /path/to/website/files/] escaping for redirect - - [21/Sep/2011:21:27:07 +1000] [][rid#95330f8/initial] (1) [perdir /path/to/website/files/] redirect to [REDIRECT/301] - - [21/Sep/2011:21:27:07 +1000] [][rid#9535100/initial] (3) [perdir /path/to/website/files/] strip per-dir prefix: /path/to/website/files/monitor.html -> monitor.html - - [21/Sep/2011:21:27:07 +1000] [][rid#9535100/initial] (3) [perdir /path/to/website/files/] applying pattern '^/monitor\.html$' to uri 'monitor.html' - - [21/Sep/2011:21:27:07 +1000] [][rid#9535100/initial] (4) [perdir /path/to/website/files/] RewriteCond: input='' pattern='192\.168\.0\.23' => matched - - [21/Sep/2011:21:27:07 +1000] [][rid#9535100/initial] (2) [perdir /path/to/website/files/] rewrite 'monitor.html' -> '/monitor.html' - - [21/Sep/2011:21:27:07 +1000] [][rid#9535100/initial] (2) [perdir /path/to/website/files/] explicitly forcing redirect with - - [21/Sep/2011:21:27:07 +1000] [][rid#9535100/initial] (1) [perdir /path/to/website/files/] escaping for redirect - - [21/Sep/2011:21:27:07 +1000] [][rid#9535100/initial] (1) [perdir /path/to/website/files/] redirect to [REDIRECT/301]

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

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


  • Bingo! (filler to satisfy the 15 character minimum) – John Gardeniers Sep 26 '11 at 2:05
  • Oops. I was too quick on the trigger. The redirect certainly works but it's redirecting every request to /monitor.html – John Gardeniers Sep 26 '11 at 2:09
  • Double oops. I tested by removing the "3" from the address but of course 192\.168\.0\.2 still matches I need to slow down and concentrate more. :( – John Gardeniers Sep 26 '11 at 2:11
  • :( Something to do with the Condition. Let me double check. – SparX Sep 26 '11 at 2:12
  • ^192\.168\.0\.2$ – Shane Madden Sep 26 '11 at 2:14

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)

  • I don't understand why but I'm still getting a redirection look. Sure looks like it should work. – John Gardeniers Sep 26 '11 at 0:30
  • Try using REMOTE_ADDR instead of REMOTE_HOST. – Steven Monday Sep 26 '11 at 1:25
  • @JohnGardeniers I've got nothing. Maybe set a RewriteLog and RewriteLogLevel 9, see if that gives us anything interesting? – Shane Madden Sep 26 '11 at 1:27
  • Question updated. – John Gardeniers Sep 26 '11 at 1:59
  • @JohnGardeniers Oh, it's in .htaccess, missed that. Just drop the / from the match. RewriteRule !^monitor\.html$ /monitor.html [R=301,L] – Shane Madden Sep 26 '11 at 2:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.