0

I got the documentroot set up like this: var/www/html

What I'm trying to do is:

cms.domain.com --> var/www/html/cms

domain.com --> var/www/html/cms/sites/site1

I'm trying to accomplish this by using virtualhosts. The problem is I can't set a VirtualDocumentRoot for each (sub)domain because the sites use a bunch of scripts and configs, located in var/www/html/includes which are supposed to stay non public, and the apps call these with $_SERVER["document_root"].

What I've tried is this:

<VirtualHost *:80> ServerName domain.com ServerAlias *.domain.com ServerAlias www.domain.com AliasMatch ^(.*)$ /cms/sites/site1/ DocumentRoot /var/www/html <Directory /var/www/html> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <IfModule mod_dir.c> DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm </IfModule> </VirtualHost> 

and for the subdomain:

<VirtualHost *:80> ServerName cms.domain.com ServerAlias *.cms.domain.com AliasMatch ^(.*)$ /cms/ DocumentRoot /var/www/html <Directory /var/www/html> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <IfModule mod_dir.c> DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm </IfModule> </VirtualHost> 

Doesn't work. I guess what I'm actually looking for is something to append the path after documentroot while keeping documentroot how it is.

3
  • It could be helpful to the reader to know what "Doesn't work" means. Where does apache pick the html files up from, when you GET cms.domain.com or respectively domain.com? Commented Dec 2, 2017 at 23:47
  • 1
    One problem could be that cms.domain.com (2nd VirtualHost) is a subset of *.domain.com (first VirtualHost). So without studying the apache docu in detail, I can't say if apache will apply the 1st or the 2nd VirtualHost config, if you do a GET cms.domain.com. Commented Dec 2, 2017 at 23:50
  • directories which are supposed to be "non-public" should never be in documentroot. Use ScriptAlias or similar to link to those. Commented Dec 4, 2017 at 8:14

1 Answer 1

0

You have a lot of conflicting configuration here. I would suggest creating a VirtualHost for domain.com and www.domain.com and another for *.domain.com and/or *.cms.domain.com with the AliasMatch. There is also precedence in VirtualHosts so domain.com should be last.

The easiest way out of the common config issue is to symlink /var/www/html/includes to each VirtualHost directory and then you at least have consistency.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.