Index File for Subdomains

jlandes

Verified User
Joined
Dec 1, 2005
Messages
561
Location
Lewistown, Pennsylvania, USA
As many of you may already know, whenever subdomains are added within DirectAdmin, no default index file is created in the subdomains root directory. This may have a tendency to confuse some users, as they think their subdomains are not working correctly because when they try to view them they get an error until an index file is placed in the directory.

I have been able to resolve the issue on my system by doing the following:

First, create the file subdomain_placeholder.html in the directory /usr/local/directadmin/data/templates/custom/. Then, place the following code in the file.

Code:
<html>
<head>
        <title>
                |SUBDOMAIN|
        </title>
 
        <style>
        * { font-family: verdana; font-size: 10pt; COLOR: gray; }
        b { font-weight: bold; }
        table { border: 1px solid gray;}
        td { text-align: center; padding: 25;}
 
        </style>
</head>
<body>
<center>
<br><br><br><br>
        <table>
        <tr><td>This is a placeholder for the subdomain <b>|SUBDOMAIN|</b></td></tr>
        </table>
<br><br>
 
</center>
</body>
 
</html>

Now chmod the file to 644 and chown to diradmin:diradmin.

Next, create the file subdomain_create_post.sh in the directory /usr/local/directadmin/scripts/custom/ if it does not already exist and add the following code to it. If it does already exist, just add the code to the file that is already there. Follow the normal DirectAdmin recommended method for creating this file, chowning it, and chmoding it.

Code:
#!/bin/sh
 
#Create default index page for the subdomain
TEMPLATE_DIR=/usr/local/directadmin/data/templates/custom
TEMPLATE_FILE=$TEMPLATE_DIR/subdomain_placeholder.html
DEST_DIR=/home/$username/domains/$domain/public_html/$subdomain
DEST_FILE=$DEST_DIR/index.html
 
cp $TEMPLATE_FILE $DEST_FILE
chmod 644 $DEST_FILE
chown $username:$username $DEST_FILE
 
STR="perl -pi -e 's/\|SUBDOMAIN\|/$subdomain.$domain/' $DEST_FILE"
eval $STR;
 
exit 0;

I'd be interested in hearing your thoughts about what I've done here. Are there any recommendations?

I have contacted DirectAdmin and have asked them if it would be possible to have an index file automatically created when new subdomains are added, much like what is done when a regular domain is added.
 
First to jlandes thanks for taking the time to share this feature with the DA community.

To avoid confusion when the "Forbidden" error appears, DA will now create a basic index.html if it does not exists in the subdomain's folder.

Is there a way to make it check for index.htm and index.php as well?
I just transfered about 500 domains from one server to another and didn't know about this new feature. During the account creation and restore some of those sub domains already had an index.htm file ,but an index.html file was still added. The .html file took presidence over the .htm file and so the message appeared (This is a placeholder for the subdomain). :eek:

Thanks,

Jason
 
Hello,

I've added extra checks for htm, php, php4, php5, php6, cgi, shtml, asp extensions on the index's. Let me know if I've missed any. (Doing the index.* is slightly harder in c++ than just checking a series of files)
Available for the next release.

John
 
Back
Top