7

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:

  • 127.0.0.1 example.local
  • 127.0.0.1 foo.example.local

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

Comments

1

XAMPP 7.3.7 (INFINITE *.LOCALHOST) + SOME SYMFONY v4 DOMAINS

Edit and activate the Apache "vhost alias module" (Uncomment the #)

FILE=C:\xampp\apache\conf\httpd.conf

LoadModule vhost_alias_module modules/mod_vhost_alias.so 

FILE=C:\xampp\apache\conf\extra\httpd-vhosts.conf

Edit with this, works OK with Chrome (Not Firefox)

############################# ## LOCALHOST ############################# <VirtualHost *:80> UseCanonicalName Off DocumentRoot "C:/xampp/htdocs/" ServerName localhost </VirtualHost> ############################# ## SYMFONY VHOSTS (/public) ############################# <VirtualHost *:80> UseCanonicalName Off DocumentRoot "C:/xampp/htdocs/symfonyapi/public/" ServerName symfonyapi.localhost <Directory C:/xampp/htdocs/symfonyapi/public/> AllowOverride All Order Allow,Deny Allow from All </Directory> </VirtualHost> <VirtualHost *:80> UseCanonicalName Off DocumentRoot "C:/xampp/htdocs/symfonyweb/public/" ServerName symfonyweb.localhost <Directory C:/xampp/htdocs/symfonyweb/public/> AllowOverride All Order Allow,Deny Allow from All </Directory> </VirtualHost> ############################# ## VHOSTS *.LOCALHOST ############################# <VirtualHost *:80> UseCanonicalName Off ServerAlias *.localhost VirtualDocumentRoot "C:/xampp/htdocs/%1/" </VirtualHost> 

For HTTPS

FILE=C:\xampp\apache\conf\extra\httpd-ssl.conf

<VirtualHost _default_:443> # General setup for the virtual host # DocumentRoot "/xampp/htdocs" # ServerName www.example.com:443 # ServerAdmin [email protected] # ErrorLog "/xampp/apache/logs/error.log" # TransferLog "/xampp/apache/logs/access.log" UseCanonicalName Off ServerAlias *.localhost ServerAdmin [email protected] VirtualDocumentRoot "c:/xampp/htdocs/%1" ErrorLog "/xampp/apache/logs/%1.error.log" TransferLog "/xampp/apache/logs/%1.access.log" 

Create domains:

C:\xampp\htdocs\dev1 C:\xampp\htdocs\dev2 C:\xampp\htdocs\dev3 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.