VirtualHost - point all domains to root folder and one domain to a subfolder in the root folder

StackOverflow https://stackoverflow.com/questions/23430428

  •  14-07-2023
  •  | 
  •  

Question

I have tried but nothing seems to work for me here. I have an Apache server with multiple domains set up. Currently they all point to the root folder (C:\xampp\htdocs) but I'd like to organize things a little better here on. I'd like to use Apache's VirtualHost to point each new domain to a subfolder inside this folder but have all older websites point to C:\xampp\htdocs in the mean time until I can migrate each.

The issue is that when I use the following code, all my domains point to the subfolder

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot "C:\xampp\htdocs\newdomain\"
    ServerName www.newdomain.com
</VirtualHost>

I need to add a Virtual that listens to all other domains and points them to C:\xampp\htdocs But I'm running out of ideas. Please help

Était-ce utile?

La solution

Try that:

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
    DocumentRoot "C:\xampp\htdocs"
    ServerName _default_
</VirtualHost>
<VirtualHost *:80>
    DocumentRoot "C:\xampp\htdocs\newdomain"
    ServerName www.newdomain.com
</VirtualHost>

You need a default virtualhost, that's the catch_all thing, when the Host Header defined in the HTTP query does not match any ServerName directive the default VH is useD. And the default VH is the first one defined in the configuration.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top