You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Sa...@seagate.com on 2002/11/18 19:02:44 UTC

Re: [users@httpd] redirection based on client IP address (only first two octets) / External Rewriting Engine

Thanks Joshua, I will try this Rule.

However I have come to realize our problem is more complex, and can not be
solved via simple rewrite rules. I think I will need to use External
Rewrite Rule to perform the redirection task.
http://httpd.apache.org/docs-2.0/misc/rewriteguide.html mentions a perl
script can be written to act as the Rewrite Map. Can anyone give me
examples of such a script. How to pass in the input and what output is
expected.

Thanks
Saqib Ali



                                                                                                                         
                    Joshua Slive                                                                                         
                    <joshua@slive        To:     users@httpd.apache.org                                                  
                    .ca>                 cc:                                                                             
                    No Phone Info        Subject:     Re: [users@httpd] redirection based on client IP address (only     
                    Available            first two octets)                                                               
                                                                                                                         
                    11/18/2002                                                                                           
                    09:37 AM                                                                                             
                    Please                                                                                               
                    respond to                                                                                           
                    users                                                                                                
                                                                                                                         
                                                                                                                         




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





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


Re: [users@httpd] redirection based on client IP address (only first two octets) / External Rewriting Engine

Posted by Joshua Slive <jo...@slive.ca>.
On Mon, 18 Nov 2002 Saqib.N.Ali@seagate.com wrote:

>
> Thanks Joshua, I will try this Rule.
>
> However I have come to realize our problem is more complex, and can not be
> solved via simple rewrite rules. I think I will need to use External
> Rewrite Rule to perform the redirection task.
> http://httpd.apache.org/docs-2.0/misc/rewriteguide.html mentions a perl
> script can be written to act as the Rewrite Map. Can anyone give me
> examples of such a script. How to pass in the input and what output is
> expected.

See:
http://httpd.apache.org/docs-2.0/mod/mod_rewrite.html#rewritemap

To summarize:
Take new-line-terminated input on stdin, write output to stdout.

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