httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joshua Slive <>
Subject Re: [users@httpd] redirection based on client IP address (only first two octets)
Date Mon, 18 Nov 2002 17:37:03 GMT
On Mon, 18 Nov 2002 wrote:

> Hi All,
> I have the following REWRITE rules to redirect based upon client IP
> address. The redirection works fine. However now I want to redirect based
> on only first 2 octets of the IP address. e.g:

Something like this (untested, but it should give you the idea):

RewriteMap  redirector txt:/tmp/
RewriteCond %{REMOTE_ADDR} ^([0-9]*\.[0-9]*)\..*$
RewriteCond ${redirector:%1|NO-REDIRECT} (http://.*)
RewriteRule ^.* %1 [R,L]

Note that %1 is a back-reference to the matched portion of the last

I've also improved your rules a little by making only one lookup in the
map.  Note that the second RewriteCond will fail when the map-lookup
fails,  because NO-REDIRECT doesn't match http://.*.  Then the RewriteRule
simply uses the results of that lookup for the redirect.


The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:> for more info.
To unsubscribe, e-mail:
   "   from the digest:
For additional commands, e-mail:

View raw message