How to point a subdomain to /var/www/html/…

Kal

Verified User
Joined
Nov 18, 2019
Messages
93
Location
Australia
I created a subdomain (sub1.domain.com) in DirectAdmin. I then added the following custom HTTPD config to point the subdomain to a directory in /var/www/html:
Code:
|*if SUB="sub1"|
|?SDOCROOT=/var/www/html/`SUB`|
|?SERVER_ALIASES=`SERVER_ALIASES` sub2.`DOMAIN`|
|*endif|


It works as you might expect for HTML, but any PHP pages return a 404 with the 'No input file specified' error. The problem seems to be caused by DirectAdmin's default VirtualHost config for a subdomain, which includes a <Directory> directive. This directive isn't part of the instructions for adding global subdomain VirtualHosts, so I figured it isn't required here. Sure enough, if I manually delete it from the httpd.conf file, the error goes away.

But of course, manual edits to httpd.conf will get overwritten. So my question is, how can I remove the <Directory> directive from my subdomain using DirectAdmin's Custom HTTPD Configurations feature?
 

Kal

Verified User
Joined
Nov 18, 2019
Messages
93
Location
Australia
I guess the Custom HTTPD feature only allows adding code, not removing it.

So I tackled the problem from the other end… I added a new VirtualHost entry to the virtual_host2.conf.CUSTOM.4.post file and wrapped it in an if-statement so it only applies to the targeted domain:
Code:
|*if DOMAIN="domain.com"|
<VirtualHost |IP|:|PORT_80| |MULTI_IP|>
    ServerName sub1.|DOMAIN|
    ServerAlias sub1.|DOMAIN| sub2.|DOMAIN|
    DocumentRoot /var/www/html/sub1
    …
</VirtualHost>

<VirtualHost |IP|:|PORT_443| |MULTI_IP|>
    ServerName sub1.|DOMAIN|
    ServerAlias sub1.|DOMAIN| sub2.|DOMAIN|
    DocumentRoot /var/www/html/sub1
    …
</VirtualHost>
|*endif|

This meant I could delete the subdomain in DirectAdmin—along with its DA-generated VirtualHost and its redundant directory.
 

floyd

Verified User
Joined
Mar 29, 2005
Messages
5,870
Thanks for letting us know your solution. I am sure it will help others in the future.
 
  • Like
Reactions: Kal
Top