Updating, recompiling, VirtualHost templates, customizations, php safemode …How do I change the DocumentRoot of only one of my subdomains?
As of DirectAdmin 1.59.5, the support for a subdomain document root override file has been add:
You can now use this override file to set a given DocumentRoot for any subdomain (per-https/https control). GUI to follow for Users just set this file through 2222.
Until the User GUI is added, the Admin GUI can be use with the new SDOCROOT tokens (requires 1.59.5+) for any webserver type, without the need for custom templates.
Let’s assume that you want to change the DocumentRoot for .domain.com:
- Admin Level -> Custom Httpd Config -> domain.com
- in the |CUSTOM| token, you can specify any path you would like to the SDOCROOT token. If you want it relative to the current domain.com/public_html, you’d use:
which would place it in /home/user/domains/domain.com/public_html/othersub
- Or if you wish it to be something fully out of the public_html/private_html, you could set it like:
which would place it in /home/user/domains/domain.com/subdomains/sub
The full list of available tokens can be view from the “Available Tokens” button in the Custom Httpd Config, when viewing the domain.
The OLD METHOD
1) If you wish to change only 1 sub-domain path, you’d use this guide as a starting point:
Then insert the following code:
This will do a check on the subdomain name.
Change subname to the name of the subdomain you want to set the path for.
Also change the path to the path you’d like.
Failing to use the if statement on the subdomain will cause the main domain and all subdomains to use this new path, which isn’t always as desired.
2) Going into more detail, the DocumentRoot for a subdomain will always have the “sub” name appended to the end. If this is not the desired effect, then the templates would have to be modify to get rid of the bit on the end, while still allowing subdomain paths for normal subdomains to be valid.
For doing that, first copy the templates to the custom folder
cp ../virtual_host2*_sub.conf .
Then edit both of the virtual_host2_sub.conf and virtual_host2_secure_sub.conf files.
Find the following line:
and change it to be:
The Same thing for this line:
|?CGI=ScriptAlias /cgi-bin/ `DOCROOT`/`SUB`/cgi-bin/|
Then change it to be:
|?CGI=ScriptAlias /cgi-bin/ `DOCROOT`/cgi-bin/|
and one last time for a 3rd line, Do change:
Save the 2 virtual_host2*_sub.conf with these 3 changes, then proceed with step 1 normally, and the path will be what you’re looking for.
since we just moved the SUB part from the bottom, and moved it to the top, All existing subdomains will also remain unaffected,
3)Similarly, if you only which to change the path of the domain and not any subdomains, you can use
so that only if there is no subdomain name, then the path will be alter.