0

I have an Apache webserver behind a load balancer which proxies request to Apache and have problem regarding configuring directories.

Here is my scenario:

  1. Upper Load Balancer proxies request to Apache with adding original Hostname in X-Forwarded-Host.
  2. I should decide which directory to serve based on X-Forwarded-Host header value.
  3. Incoming requests have X-Forwarded-Host headers like:
    test1.example.com
    test2.example.com
    test3.example.com
  4. Here is my desired behavior:
    Each request must be served from:
    %{DocumentRoot}/test1/
    %{DocumentRoot}/test2/
    %{DocumentRoot}/test3/
  5. I wrote something like this, but it needs to be corrected:
RewriteCond "%{HTTP:X-Forwarded-Host}" "^[^.]*"
RewriteRule "^(.*)" "%{DOCUMENT_ROOT}/%1/$1" [L]

Any help on how to write Rewrite Rule?

1 Answers1

0

You need to put your RewriteCond pattern in parenthesis, like this:

RewriteCond "%{HTTP:X-Forwarded-Host}" "^([^.]*)"
RewriteRule "^(.*)" "%{DOCUMENT_ROOT}/%1/$1" [L]