Custom document root for subdomain

elbarto

Verified User
Joined
Oct 8, 2008
Messages
133
Hi, guys.

I have a client who has many domains and wants to change the document root for two subdomains of some of his domains.

Let's say he wants to have the following

- aaa.domain1.com - /home/user/domains/domain1.com/public_html/aaa/public
- bbb.domain2.com - /home/user/domains/domain2.com/public_html/bbb/public

He has created both subdomains. So I went to the httpd.conf customization page and added the following:

Code:
|*if SUB="aaa"|
|?DOCROOT=/home/user/domains/domain1.com/public_html/aaa/public|
|*endif|

|*if SUB="bbb"|
|?DOCROOT=/home/user/domains/domain2.com/public_html/bbb/public|
|*endif|

I saved it and when I check what it did, I see the following.

The VirtualHost for aaa.domain1.com shows the following:

Code:
DocumentRoot /home/user/domains/domain1.com/public_html/aaa/public/aaa

And the VirtualHost for bbb.domain2.com does not show any changes.

What should I do to:
- apply the changes to both domains/subdomains?
- avoid DA to add the subdomain name to the document root I define?

Thanks!
 
Hello,

That's the correct solution, but to prevent the subdomain from being appended to the end of the DocumenRoot, you'd need to edit the templates.

Using this guide:
http://help.directadmin.com/item.php?id=2

Edit the 2 virtual_host2*sub.conf subdomain files.
In those 2 conf files, you'll find something like this:
Code:
|?DOCROOT=`HOME`/domains/`DOMAIN`/public_html|
...
|?CGI=ScriptAlias /cgi-bin/ `DOCROOT`/`SUB`/cgi-bin/|
...
        DocumentRoot |DOCROOT|/|SUB|
...
        <Directory |DOCROOT|/|SUB|>
...
In the custom/virtual_host2*sub.conf files (copied from the originals) you'll want to change those lines to show this instead:
Code:
|?DOCROOT=`HOME`/domains/`DOMAIN`/public_html/[b]`SUB`[/b]|
...
|?CGI=ScriptAlias /cgi-bin/ `DOCROOT`/cgi-bin/|
...
        DocumentRoot |DOCROOT|
...
        <Directory |DOCROOT|>
...
Which puts the subdomain part into the DOCROOT variable instead. That way your override of the DOCROOT actually applies correctly into all uses.
Change public_html to private_html in the virtual_host2_secure_sub.conf file.

John
 
Thanks for your help. That worked for subdomain aaa.domain1.com but I'm still not being able to apply it for bbb.domain2.com
 
OK, I found my error.
I was placing the code for both subdomains in the are for the domain domain1.com. I moved the code for subdomain "bbb" to the area of domain2.com and it's working.
 
Back
Top