2

Is it possible to have 2 web servers running on the same box with different ports and then use htaccess to tunnel traffic from 1 server to another based on a rewritecond? Basically when a certain condition is met I want the request to be handled by my other web server and I don't want to return a moved response.

Will
  • 257
  • 4
  • 19

1 Answers1

2

Yes, it's possible. If the first server is Apache, you can use it as a reverse proxy using mod_proxy to do this.

ProxyPass /abc http://second-web-server.yourdomain.com/def
ProxyPassReverse /abc http://second-web-server.yourdomain.com/def

http://httpd.apache.org/docs/2.0/mod/mod_proxy.html#proxypass

If your proxy requirement is more complex, you can also tell mod_rewrite to send the substitution part of the rewrite rule to mod_proxy with the "P" flag:

RewriteRule ^/abc$ http://second-web-server.yourdomain.com/def [P]

It appears (I'm not familiar with litespeed) that the litespeed rewrite engine is identical to Apache:

http://www.litespeedtech.com/docs/webserver/config/rewrite/

So to test for the absence of a cookie, you'd use a Rewrite rule like so:

RewriteCond %{HTTP_COOKIE}       !^Your_Cookie_Name$
RewriteRule ^/(.*)               http://second-web-server.yourdomain.com/$1 [p]

There's an example of litespeed rewrite+proxy here:

http://www.litespeedtech.com/support/forum/showthread.php?t=2879

Hari
  • 211
  • 1
  • 3
  • What if I want to pass to the proxy only if a cookie is not set? Also the first server is litespeed. – Will Mar 21 '11 at 04:36
  • 1
    I've edited the answer with a cookie example and some links to litespeed. – Hari Mar 21 '11 at 05:55