0

I have two domains:

domain1.com
domain2.com

I have one Apache 2 server, with a document root /svr.

I want the following to occur:

  • domain1.com routes to the equivalent of /svr/examplepath/thisisadir/param/domain1
  • domain2.com routes to the equivalent of /svr/examplepath/thisisadir/param/domain2

I have tried using a .htaccess with RewriteEngine in /svr, using VirtualHost declarations in sites-available for each hostname and simply using 301 redirects. However, I can't use a simple 301, as the user should still see domain1.com in their browser.

I.e. domain1.com/about-this-site should map to /svr/examplepath/thisisadir/param/domain1/about-this-site.

I can't get RewriteEngine to route the hostnames to their respective endpoints, any advice would be much appreciated. I'm currently attempting to use HTTP_HOST in a .htaccess in the server root, but the rewrite rules still aren't taking effect.

Ilmiont

  • "using VirtualHost declarations in sites-available for each hostname" - and what was the problem with this? Using a VirtualHost container would seem to be the preferred solution here (although with _different_ DocumentRoots), as Jonah states in his answer. Is the "one DocumentRoot" a requirement here? – MrWhite Sep 11 '16 at 21:55

1 Answers1

2

Stop using .htaccess and RewriteEngine, and look instead at the apache directive called "VirtualHost":

http://httpd.apache.org/docs/current/vhosts/name-based.html

This is the problem they solve. Apache will match the incoming Host: header to the ServerName directives in the VirtualHost blocks and apply the configuration from matching VirtualHost. Each VirtualHost can have its own DocumentRoot.

The below can be the skeleton of a solution:

 <VirtualHost *:80>
   ServerName domain1.com
   DocumentRoot /svr/examplepath/thisisadir/param/domain1
   # other configuration here
 </VirtualHost>
 <VirtualHost *:80>
   ServerName domain2.com
   DocumentRoot /svr/examplepath/thisisadir/param/domain2
   # other configuration here
 </VirtualHost>
Jonah Benton
  • 1,252
  • 7
  • 13