Wildcard domain pointed to specific directory?

Gta-multi

Verified User
Joined
Aug 14, 2010
Messages
17
Hi,

I wonder if it's possible to have a wildcard domain which points all the unset subdomains to one specific directory
All other existing just act normal

Example:
[table="width: 500, class: grid"]
[tr]
[td]Domain[/td]
[td]Directory[/td]
[/tr]
[tr]
[td]mydomain.com[/td]
[td]/public/myuser/domains/mydomain.com/public_html[/td]
[/tr]
[tr]
[td]www.mydomain.com[/td]
[td]/public/myuser/domains/mydomain.com/public_html[/td]
[/tr]
[tr]
[td]admin.mydomain.com[/td]
[td]/public/myuser/domains/mydomain.com/public_html/admin[/td]
[/tr]
[tr]
[td]randomSubDomain.mydomain.com[/td]
[td]/public/myuser/domains/mydomain.com/public_html/allsubs[/td]
[/tr]
[tr]
[td]anotherRandom.mydomain.com[/td]
[td]/public/myuser/domains/mydomain.com/public_html/allsubs[/td]
[/tr]
[tr]
[td]anyOtherRandom.mydomain.com[/td]
[td]/public/myuser/domains/mydomain.com/public_html/allsubs[/td]
[/tr]
[/table]

The last three examples can be any string/subdomain.

I already tried something with "Custom HTTPD Configurations" but that didn't work well.

Any help?
 
We don't know what exactly did not work for you. The guide is working, I've tested it some time earlier.
The order of subdomains is very important here. Your wildcard should be the lowest in config file.

Kindly provide your httpd.conf/nginx.conf for a specific domain (as how you have it), or get someone to configure it for you. There is no other way to help you.
 
My custom httpd.conf for the domain is:

Code:
|*if SUB|
    |?DOCROOT=/home/myuser/domains/mydomain.com/public_html/allsubs/public|
    ServerAlias *.|DOMAIN|
|*endif|

|*if !SUB|
    |?DOCROOT=/home/myuser/domains/mydomain.com/public_html/public|
|*endif|

I'm using laravel, thats why it needs to use to the public folder
 
Kindly provide entire config for a domain in order to see whether or not DOCROOT changes on your server.

I noticed the problem.

By default directadmin adds the subdomain name after the document root. If i want laravel to work i can't have that.

Code:
|*if SUB="rooster"|
    ServerAlias *.|DOMAIN|
    |?DOCROOT=/home/myuser/domains/mydomain.com/public_html/rooster/public|
|*endif|

Code:
AH00112: Warning: DocumentRoot [/home/myuser/domains/mydomain.com/public_html/rooster/public/rooster] does not exist
AH00112: Warning: DocumentRoot [/home/myuser/domains/mydomain.com/public_html/rooster/public/rooster] does not exist
Syntax OK
Those are the errors i get because of the added "rooster" thing.


FULL HTTPD CONFIG:

Code:
# Auto generated apache config file by DirectAdmin version 1.51.3
# Modifying this file is not recommended as any changes you make will be
# overwritten when the user makes any changes to their website

# For global config changes that affect all Users, see this guide:
# http://help.directadmin.com/item.php?id=2
# For local config changes that only affect one User, see this guide:
# http://help.directadmin.com/item.php?id=3


<Directory "/home/myuser/public_html">
	<IfModule mod_ruid2.c>
		RMode config
		RUidGid mydomain mydomain
		#RGroups apache access
		RGroups @none
	</IfModule>
	<IfModule mod_fcgid.c>
		SuexecUserGroup mydomain mydomain
	</IfModule>
		php_admin_flag engine ON
		php_admin_value sendmail_path '/usr/sbin/sendmail -t -i -f [email protected]'
		php_admin_value mail.log /home/myuser/.php/php-mail.log
		php_admin_value open_basedir /home/myuser/:/tmp:/var/tmp:/usr/local/lib/php/:/usr/local/php56/lib/php/
</Directory>

<VirtualHost 141.138.140.244:80 >
	ServerName www.mydomain.com
	ServerAlias www.mydomain.com mydomain.com 
	ServerAdmin [email protected]
	DocumentRoot /home/myuser/domains/mydomain.com/public_html
	UseCanonicalName OFF
	<IfModule !mod_ruid2.c>
		SuexecUserGroup mydomain mydomain
	</IfModule>
	<IfModule mod_ruid2.c>
		RMode config
		RUidGid mydomain mydomain
		#RGroups apache access
		RGroups @none
	</IfModule>
	CustomLog /var/log/httpd/domains/mydomain.com.bytes bytes
	CustomLog /var/log/httpd/domains/mydomain.com.log combined
	ErrorLog /var/log/httpd/domains/mydomain.com.error.log
	<Directory /home/myuser/domains/mydomain.com/public_html>
		AllowOverride AuthConfig FileInfo Indexes Limit Options=Indexes,Includes,IncludesNOEXEC,MultiViews,SymLinksIfOwnerMatch,FollowSymLinks,None
		Options -ExecCGI
		php_admin_flag engine ON
		php_admin_value sendmail_path '/usr/sbin/sendmail -t -i -f [email protected]'
		php_admin_value mail.log /home/myuser/.php/php-mail.log
		php_admin_value open_basedir /home/myuser/:/tmp:/var/tmp:/usr/local/lib/php/:/usr/local/php56/lib/php/
	</Directory>
</VirtualHost>

<VirtualHost 141.138.140.244:443 >
	SSLEngine on
	SSLCertificateFile /etc/httpd/conf/ssl.crt/server.crt
	SSLCertificateKeyFile /etc/httpd/conf/ssl.key/server.key
	SSLCACertificateFile /etc/httpd/conf/ssl.crt/server.ca
	ServerName www.mydomain.com
	ServerAlias www.mydomain.com mydomain.com 
	ServerAdmin [email protected]
	DocumentRoot /home/myuser/domains/mydomain.com/private_html
	UseCanonicalName OFF
	<IfModule !mod_ruid2.c>
		SuexecUserGroup mydomain mydomain
	</IfModule>
	<IfModule mod_ruid2.c>
		RMode config
		RUidGid mydomain mydomain
		#RGroups apache access
		RGroups @none
	</IfModule>
	CustomLog /var/log/httpd/domains/mydomain.com.bytes bytes
	CustomLog /var/log/httpd/domains/mydomain.com.log combined
	ErrorLog /var/log/httpd/domains/mydomain.com.error.log
	<Directory /home/myuser/domains/mydomain.com/private_html>
		AllowOverride AuthConfig FileInfo Indexes Limit Options=Indexes,Includes,IncludesNOEXEC,MultiViews,SymLinksIfOwnerMatch,FollowSymLinks,None
		Options -ExecCGI
		php_admin_flag engine ON
		php_admin_value sendmail_path '/usr/sbin/sendmail -t -i -f [email protected]'
		php_admin_value mail.log /home/myuser/.php/php-mail.log
		php_admin_value open_basedir /home/myuser/:/tmp:/var/tmp:/usr/local/lib/php/:/usr/local/php56/lib/php/
	</Directory>
</VirtualHost>

<VirtualHost 141.138.140.244:80 >
	ServerName www.admin.mydomain.com
	ServerAlias www.admin.mydomain.com admin.mydomain.com 
	ServerAdmin [email protected]
	DocumentRoot /home/myuser/domains/mydomain.com/public_html/admin
	UseCanonicalName OFF
	<IfModule !mod_ruid2.c>
		SuexecUserGroup mydomain mydomain
	</IfModule>
	<IfModule mod_ruid2.c>
		RMode config
		RUidGid mydomain mydomain
		#RGroups apache access
		RGroups @none
	</IfModule>
	CustomLog /var/log/httpd/domains/mydomain.com.admin.bytes bytes
	CustomLog /var/log/httpd/domains/mydomain.com.admin.log combined
	ErrorLog /var/log/httpd/domains/mydomain.com.admin.error.log
	<Directory /home/myuser/domains/mydomain.com/public_html>
		AllowOverride AuthConfig FileInfo Indexes Limit Options=Indexes,Includes,IncludesNOEXEC,MultiViews,SymLinksIfOwnerMatch,FollowSymLinks,None
		Options -ExecCGI
		php_admin_flag engine ON
		php_admin_value sendmail_path '/usr/sbin/sendmail -t -i -f [email protected]'
		php_admin_value mail.log /home/myuser/.php/php-mail.log
		php_admin_value open_basedir /home/myuser/:/tmp:/var/tmp:/usr/local/lib/php/:/usr/local/php56/lib/php/
	</Directory>
</VirtualHost>

<VirtualHost 141.138.140.244:443 >
	SSLEngine on
	SSLCertificateFile /etc/httpd/conf/ssl.crt/server.crt
	SSLCertificateKeyFile /etc/httpd/conf/ssl.key/server.key
	SSLCACertificateFile /etc/httpd/conf/ssl.crt/server.ca	
	ServerName www.admin.mydomain.com
	ServerAlias www.admin.mydomain.com admin.mydomain.com 
	ServerAdmin [email protected]
	DocumentRoot /home/myuser/domains/mydomain.com/private_html/admin
	UseCanonicalName OFF
	<IfModule !mod_ruid2.c>
		SuexecUserGroup mydomain mydomain
	</IfModule>
	<IfModule mod_ruid2.c>
		RMode config
		RUidGid mydomain mydomain
		#RGroups apache access
		RGroups @none
	</IfModule>
	CustomLog /var/log/httpd/domains/mydomain.com.admin.bytes bytes
	CustomLog /var/log/httpd/domains/mydomain.com.admin.log combined
	ErrorLog /var/log/httpd/domains/mydomain.com.admin.error.log
	<Directory /home/myuser/domains/mydomain.com/private_html>
		AllowOverride AuthConfig FileInfo Indexes Limit Options=Indexes,Includes,IncludesNOEXEC,MultiViews,SymLinksIfOwnerMatch,FollowSymLinks,None
		Options -ExecCGI
		php_admin_flag engine ON
		php_admin_value sendmail_path '/usr/sbin/sendmail -t -i -f [email protected]'
		php_admin_value mail.log /home/myuser/.php/php-mail.log
		php_admin_value open_basedir /home/myuser/:/tmp:/var/tmp:/usr/local/lib/php/:/usr/local/php56/lib/php/
	</Directory>
</VirtualHost>

<VirtualHost 141.138.140.244:80 >
    ServerAlias *.mydomain.com
	ServerName www.rooster.mydomain.com
	ServerAlias www.rooster.mydomain.com rooster.mydomain.com 
	ServerAdmin [email protected]
	DocumentRoot /home/myuser/domains/mydomain.com/public_html/rooster/public/rooster
	UseCanonicalName OFF
	<IfModule !mod_ruid2.c>
		SuexecUserGroup mydomain mydomain
	</IfModule>
	<IfModule mod_ruid2.c>
		RMode config
		RUidGid mydomain mydomain
		#RGroups apache access
		RGroups @none
	</IfModule>
	CustomLog /var/log/httpd/domains/mydomain.com.rooster.bytes bytes
	CustomLog /var/log/httpd/domains/mydomain.com.rooster.log combined
	ErrorLog /var/log/httpd/domains/mydomain.com.rooster.error.log
	<Directory /home/myuser/domains/mydomain.com/public_html/rooster/public>
		AllowOverride AuthConfig FileInfo Indexes Limit Options=Indexes,Includes,IncludesNOEXEC,MultiViews,SymLinksIfOwnerMatch,FollowSymLinks,None
		Options -ExecCGI
		php_admin_flag engine ON
		php_admin_value sendmail_path '/usr/sbin/sendmail -t -i -f [email protected]'
		php_admin_value mail.log /home/myuser/.php/php-mail.log
		php_admin_value open_basedir /home/myuser/:/tmp:/var/tmp:/usr/local/lib/php/:/usr/local/php56/lib/php/
	</Directory>
</VirtualHost>

<VirtualHost 141.138.140.244:443 >
    ServerAlias *.mydomain.com
	SSLEngine on
	SSLCertificateFile /etc/httpd/conf/ssl.crt/server.crt
	SSLCertificateKeyFile /etc/httpd/conf/ssl.key/server.key
	SSLCACertificateFile /etc/httpd/conf/ssl.crt/server.ca	
	ServerName www.rooster.mydomain.com
	ServerAlias www.rooster.mydomain.com rooster.mydomain.com 
	ServerAdmin [email protected]
	DocumentRoot /home/myuser/domains/mydomain.com/public_html/rooster/public/rooster
	UseCanonicalName OFF
	<IfModule !mod_ruid2.c>
		SuexecUserGroup mydomain mydomain
	</IfModule>
	<IfModule mod_ruid2.c>
		RMode config
		RUidGid mydomain mydomain
		#RGroups apache access
		RGroups @none
	</IfModule>
	CustomLog /var/log/httpd/domains/mydomain.com.rooster.bytes bytes
	CustomLog /var/log/httpd/domains/mydomain.com.rooster.log combined
	ErrorLog /var/log/httpd/domains/mydomain.com.rooster.error.log
	<Directory /home/myuser/domains/mydomain.com/public_html/rooster/public>
		AllowOverride AuthConfig FileInfo Indexes Limit Options=Indexes,Includes,IncludesNOEXEC,MultiViews,SymLinksIfOwnerMatch,FollowSymLinks,None
		Options -ExecCGI
		php_admin_flag engine ON
		php_admin_value sendmail_path '/usr/sbin/sendmail -t -i -f [email protected]'
		php_admin_value mail.log /home/myuser/.php/php-mail.log
		php_admin_value open_basedir /home/myuser/:/tmp:/var/tmp:/usr/local/lib/php/:/usr/local/php56/lib/php/
	</Directory>
</VirtualHost>
 
Try and add

Code:
|*if SUB="rooster"|
	[FONT=Verdana]DocumentRoot [/FONT][FONT=Verdana]|HOME|/domains/|DOMAIN|/public_html/|SUB|/public
[/FONT]|*endif|


into CUSTOM 2 section in Directadmin.
 
Try and add

Code:
|*if SUB="rooster"|
	[FONT=Verdana]DocumentRoot [/FONT][FONT=Verdana]|HOME|/domains/|DOMAIN|/public_html/|SUB|/public
[/FONT]|*endif|


into CUSTOM 2 section in Directadmin.

Thanks that works perfectly!

Just one more question. Is it also possbile to assign an private ip to this wildcard subdomain.
So the normal site goes through 12.34.56.78 and the wildcard goes to 12.34.56.79
With this method i can point any domain with an A record to 12.34.56.79 to the wildcard directory
 
Back
Top