Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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

share|improve this answer
    
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 4:36
1  
I've edited the answer with a cookie example and some links to litespeed. –  Hari Mar 21 '11 at 5:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.