httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joshua Slive <jos...@slive.ca>
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 Saqib.N.Ali@seagate.com 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/redirector.map
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
RewriteCond.

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.

Joshua.



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message