I read through the other post but none seemed to answer the question i have been having. Is it possible to have wildcard Subdomains of wildcard Domains (even if its just for subdomains and not sub-subdomains) like: foo.example.local. I already have example.local working but i can't figure out how to get foo.example.local to grab the files from the folder /sub/foo within the /example folder. My config at this moment (httpd-vhost.conf):
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:/xampp/www"
ServerName localhost
ServerAlias localhost
</VirtualHost>
<Virtualhost *:80>
VirtualDocumentRoot "C:/xampp/www/%-2"
ServerName domain.local
ServerAlias *.local
<Directory "C:/xampp/www/*">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</Virtualhost>
<Virtualhost *:80>
VirtualDocumentRoot "C:/xampp/www/%-2/sub/%-3"
ServerName sub.domain.local
ServerAlias *.*.local
<Directory "C:/xampp/www/*/sub/*">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</Virtualhost>
What currently happens is that the foo.example.local simply goes to the example folder and not to the example/sub/foo folder which is what i want it to do.
Oh and i have already enabled: LoadModule vhost_alias_module modules/mod_vhost_alias.so
within httpd.conf
Host file contains both lines:
A wildcard subdomain is particularly useful if you desire subdomains to display whatever you set as the document root (a designated folder that stores web pages.) Typically, most wildcards are set to the site's homepage out of preference. This should be specified when creating the wildcard subdomain.
A wildcard DNS record is a record in a DNS zone that will match requests for non-existent domain names. A wildcard DNS record is specified by using a * as the leftmost label (part) of a domain name, e.g. *. example.com .
How to Add Wildcard Subdomains. You can add one wildcard subdomain per each of domain names under a subscription. For this, go to Websites & Domains and add a subdomain which name is “*” to one of your domain names. Example: *.
I figured it out, to add sub-domain functionality both through wildcards i just had to use a second asterisk before in the *.domain.local to * . *.local So the final result will be as follows:
<VirtualHost *:80>
DocumentRoot "C:/xampp/www"
ServerName localhost
ServerAlias localhost
</VirtualHost>
<Virtualhost *:80>
VirtualDocumentRoot "C:/xampp/www/%-2/sub/%-3"
ServerName sub.domain.local
ServerAlias *.*.local
<Directory "C:/xampp/www/*/sub/*">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</Virtualhost>
<Virtualhost *:80>
VirtualDocumentRoot "C:/xampp/www/%-2"
ServerName domain.local
ServerAlias *.local
<Directory "C:/xampp/www/*">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</Virtualhost>
And the important part is this:
VirtualDocumentRoot "C:/xampp/www/%-2/sub/%-3"
ServerName sub.domain.local
ServerAlias *.*.local
<Directory "C:/xampp/www/*/sub/*">
Simple fix making it easy to create Sub domains within the same folder as the main domain. Allowing you to easily create multiple domains within one single project folder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With