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

For example I want to set up a forward proxy to forward HTTP requests to a.com, b.com, c.com to a.mirror.com, b.mirror.com, c.mirror.com.

Currently I have to configure 3 vhosts as:

host-a: 
  ServerName a.com
  ProxyPass / http://a.mirror.com/
host-b: 
  ServerName b.com
  ProxyPass / http://b.mirror.com/
host-c: 
  ServerName c.com
  ProxyPass / http://c.mirror.com/

Is there any way to rewrite the domain part of http request? as:

ProxyPassMatch http://(.*).com/ http://$1.mirror.com/

I wonder if I must do it by RewriteRules, but I don't know how to write the rule exactly and the performance of RewriteRule v. ProxyPass, but performance isn't a big problem.

share|improve this question

migrated from superuser.com Dec 19 '09 at 13:23

This question came from our site for computer enthusiasts and power users.

2 Answers 2

Depending on the details of your exact setup, this can be done using mod_rewrite. You would probably match on HTTP_HOST, strip out the part of the hostname that you want, and tack it onto .mirror.com, then use mod_rewrite's [P] flag to enable the proxy.

This isn't exactly what you want, but it might get you a little closer:

http://httpd.apache.org/docs/2.0/rewrite/rewrite_guide.html#uservhosts

share|improve this answer

You want something like this:

RewriteCond %{HTTP_HOST} ^(.*)\.com
RewriteRule (.*) %{SERVER_PROTOCOL}://%1.mirror.com$1 [P]

(Untested.)

share|improve this answer

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.