Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

174
Vistas
Virtualhost wildcard subdomain of wildcard subdomain in apache2.4

Currently, I have worked wildcard subdomain config like below:

<VirtualHost *:80>
    ServerAlias *.domain
    ErrorLog /tmp/error.log
    CustomLog /tmp/access.log combined
    VirtualDocumentRoot /var/www/%1/public
<Directory "/var/www">
    DirectoryIndex index.php
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
</VirtualHost>

but if I enter sub.sub.domain will return to the default vhost. How to configure to the main/root domain's path? I tried below conf but still not worked:

<VirtualHost *:80>
    ServerAlias *.*.domain
    ErrorLog /tmp/error.log
    CustomLog /tmp/access.log combined
    VirtualDocumentRoot /var/www/%2/public
<Directory "/var/www">
    DirectoryIndex index.php
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
</VirtualHost>

I changed %2 to %1 still doesn't work.

What is right syntax?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The above code has the right syntax but I just put it to the wrong placement order. So the correct answer is to put the second one to the top above the first one.

Below full config example :

<VirtualHost *:80>
    ServerAlias *.*.domain
    ErrorLog /tmp/error.log
    CustomLog /tmp/access.log combined
    VirtualDocumentRoot /var/www/%2/public
<Directory "/var/www">
    DirectoryIndex index.php
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerAlias *.domain
    ErrorLog /tmp/error.log
    CustomLog /tmp/access.log combined
    VirtualDocumentRoot /var/www/%1/public
<Directory "/var/www">
    DirectoryIndex index.php
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
</VirtualHost>

Apache is skipping/ignore the same subdomain/domain config by ascending order from the top. sub.sub.domain is also a part of *.domain , so if I want to configure it I must put the config in the top or if use different file config use lower number name.

Multiple ServerAlias or ServerName or NameVirtualHostlines will yield a "NameVirtualHost *:80 has no VirtualHosts" warning. Apache will ignore the second directive and use the first defined NameVirtualHost line, though. This seems to happen when one is using multiple virtual host configuration files and doesn't understand that you only need to define a particular NameVirtualHost line once

reference

Simple solution but I workaround for some hours and I hope it helps other people like me.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda