Search code examples
apachedrupalmod-rewritevirtualhosts

Redirecting an internal path to a virtual host


I have been working on a drupal test site for a while, which has a bunch of virtual hosts set up like this:

<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/path/to/root"
ServerName testsite1.example.com
</VirtualHost>

I have been using a modified host file to view each of these test sites, along the lines of:

12.0.0.1 localhost
20.02.2.22 testsite1.example.com
20.02.2.22 testsite2.example.com
20.02.2.22 testsite3.example.com

This has worked fine, however now I need to send the sites over to some people remotely who are not technical enough to modify their own host files and see it the way I do.

Is there a way I could set up Apache so that the url "http://20.02.2.22/testsite1" would forward to testsite1.example.com internally? I am using Drupal, and the site setup needs to see the "testsite1.example.com" so that it can correctly choose the instance to select. I have been looking through apache rewrite, but I am a bit of a newb at this so any help is much appreciated.


Solution

  • testsite1.example.com will only be resolved on your machine, so you cannot redirect. You can set up proxy with mod_proxy. Hope this works for you:

    <VirtualHost *:80>
      ServerAdmin [email protected]
      DocumentRoot "/path/to/root"
      ServerName testsite1.example.com
      ServerAlias 20.02.2.22
      <Location /testsite1/>
        ProxyPass http://testsite1.example.com/ 
      </Location>
    </VirtualHost>