Forum Moderators: phranque

Message Too Old, No Replies

Route on Client IP Address

         

sridharh

7:00 am on Mar 5, 2007 (gmt 0)

10+ Year Member



Dear All,

We are using IBM HTTP Server (Build on Apache) for our production site. I have a strange requirement to route requests from a pre-defined client to another URL. For example, request from 198.2.1.* to [10.10.11.117....] Is it possible to route request based on client IP?

Thanks & Regards,

Sridhar H

phranque

7:53 am on Mar 5, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



greetings sridhar:

try the following in the .htaccess file:

Options +FollowSymlinks
rewriteEngine on
rewriteCond %{REMOTE_ADDR} 198.2.1.*
rewriteRule (.*) [10.10.11.117...] [R=301,L]

sridharh

10:02 am on Mar 5, 2007 (gmt 0)

10+ Year Member



Thanks phranque,

Your suggestion works .. I designed my configuration as below.

<VirtualHost *:80>

ProxyRequests Off

RewriteEngine on
RewriteLog /opt/IBMIHS/logs/rewrite.txt
RewriteLogLevel 2

rewriteCond %{REMOTE_ADDR} 198.2.1.*
ProxyPass / [10.10.11.117...]
ProxyPassReverse / [10.10.11.117...]

</VirtualHost>

I am trying to route request only from the given client (remote) IP Address to move to 10.10.11.117. Other request should take the default way. But, my above condition is not working. Request from all clients are routed to the 10.10.11.117 server.

Any help would be appreciated.

Thanks & Regards,

Sridhar H

phranque

10:35 am on Mar 5, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



i don't think that RewriteCond applies to ProxyPass or ProxyPassReverse so it probably is ignored.
this might be worth a try:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_ADDR} 198.2.1.*
RewriteRule ^(.*) [10.10.11.117...] [P,L]

sridharh

11:48 am on Mar 5, 2007 (gmt 0)

10+ Year Member



Thanks again phranque,

I am looking for a proxy server rather a routing server. Our client (198.2.1.*) will not have a direct access to the server (10.10.11.117). I need to configure a proxy between client and server for this communication.

Thanks alot,

Regards,

Sridhar H

jdMorgan

4:12 pm on Mar 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Phranque's code is correct, with one small tweak:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_ADDR} ^198\.2\.1\.
RewriteRule ^/(.*) http://10.10.11.117/$1 [P,L]

As you describe the application, you do not need to (and should not) define a forward proxy (ProxyPass). You need only a reverse proxy, which can be implemented using only the mod_rewrite code that phranque provided.

Defining a forward proxy without fully-securing your server is very dangerous, and should be done only if absolutely required.

Jim