Wildcard vhost does not work as expected.

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Wildcard vhost does not work as expected.

Postby jboulhous » 27. December 2019 17:32

I also asked this question here https://stackoverflow.com/questions/59494023/redirecting-sub-sub-domains-in-a-wildcard-vhost-apache-xampp-setup

I guess here is more appropriate :-)

I am using XAMPP and Acrylic DNS Proxy on Windows 10, and I need to create several apps per day or week, these apps needs sometimes to be served from different domains, I'd like to use subdomains in this cases.

I am trying to serve several apps from an apache folder in domains(app1.jml => c:/apps/app1), so far I got this working.

But I'd like to redirect subdomains to the same domain(sub1.app1.jml => c:/apps/app1) and then let my app(php/mysql) handle the request.

Basically:
Code: Select all
app1.jml             -> c:/apps/app1    (1)
sub1.app1.jml        -> c:/apps/app1    (2)
sub2.app1.jml        -> c:/apps/app1    (2)

app2.jml             -> c:/apps/app2    (1)
sub1.app2.jml        -> c:/apps/app2    (2)
sub2.app2.jml        -> c:/apps/app2    (2)

I got (1) working with the following vhost configuration:
Code: Select all
<VirtualHost *:80>
    ServerAlias *.jml
    VirtualDocumentRoot c:/apps/%1/

    <Directory "c:/sites/">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

But I was not able to get (2). I tried the following code:

Code: Select all
<VirtualHost *:80>
    ServerAlias *.jml
    VirtualDocumentRoot c:/sites/%1/

    <Directory "c:/sites/">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerAlias *.*.jml
    VirtualDocumentRoot c:/sites/%1/

    <Directory "c:/sites/">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

It did not work, it gave me this:
Code: Select all
app1.jml             -> c:/apps/app1
sub1.app1.jml        -> c:/apps/sub1
app1.app1.jml        -> c:/apps/app1

For ServerAlias *.*.jml I tried all (%2, %0, %-1, %-2) in VirtualDocumentRoot to no avail.

Am I missing something? Thank you for your help :-)
jboulhous
 
Posts: 2
Joined: 27. December 2019 17:28
XAMPP version: 3.2.3
Operating System: Windows 10

Re: Wildcard vhost does not work as expected.

Postby Nobbie » 27. December 2019 19:14

Of course it does not work, as

*.jml

and

*.*.jml

are overlapping. For example, "sub1.app1.jml" matches "*.jml" as well as "*.*.jml". So which VirtualHost should Apache take??

You have to design your application differently somehow, so you have unique ServerNames and Alias. For example *1.jml vs. *2.jml or whatever.
Nobbie
 
Posts: 13176
Joined: 09. March 2008 13:04

Re: Wildcard vhost does not work as expected.

Postby jboulhous » 31. December 2019 16:04

Thank you @Nobbie,

My mistake! With the following configuration I made it work.
Code: Select all
<VirtualHost *:80>
    ServerAlias *.jml
    VirtualDocumentRoot c:/sites/%-2/
   
   <Directory "c:/sites/">
      Options +Indexes +Includes +FollowSymLinks +MultiViews
      AllowOverride All
      Require all granted
   </Directory>
</VirtualHost>

All the following is handled:
Code: Select all
app1.jml             -> c:/apps/app1   
sub1.app1.jml        -> c:/apps/app1
sub2.app1.jml        -> c:/apps/app1

app2.jml             -> c:/apps/app2   
sub1.app2.jml        -> c:/apps/app2   
sub2.app2.jml        -> c:/apps/app2   


Thank you.
jboulhous
 
Posts: 2
Joined: 27. December 2019 17:28
XAMPP version: 3.2.3
Operating System: Windows 10


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 198 guests