ilmiont
ilmiont

Reputation: 2161

Using rewrite engine to route multiple domains to different paths on one server

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:

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

Upvotes: 0

Views: 47

Answers (1)

Dusan Bajic
Dusan Bajic

Reputation: 10899

DocumentRoot directive sets the directory from which httpd will serve files and it is allowed in <VirtualHost> Context, so you can do something like this in your .conf files:

<VirtualHost *:80>
  ServerName domain1.example.com
  DocumentRoot /svr/examplepath/thisisadir/param/domain1
  ...
</VirtualHost>

<VirtualHost *:80>
  ServerName domain2.example.com
  DocumentRoot /svr/examplepath/thisisadir/param/domain2
  ...
</VirtualHost>

Upvotes: 1

Related Questions