1
votes

How to configure Apache to automatically for ltd2

File /etc/apache2/sites-available/default

<VirtualHost *:80>
ServerName %-3.0.%-2.0.localhost
VirtualDocumentRoot /var/www/localhost/%-3.0.%-2.0/www
</VirtualHost>

File /var/www/localhost/foo/www/index.html

File /var/www/localhost/bar/www/index.html

Url http://foo.localhost

Url http://bar.localhost

Thank you.

1
What do you mean by ltd2? What exactly do you want your apache to do? Map the URLs you gave us to the files you named? - Johannes H.
When the URL: foo.localhost want to load a file from /var/www/localhost/foo/index.html, When the URL: bar.localhost want to load a file from /var/www/localhost/bar/index.html. Thank you - Veronika Lipská

1 Answers

0
votes

Although I have never dealt with mod_vhost_alias, this should do it:

<VirtualHost *:80>
    ServerName localhost
    ServerAlias *.localhost
    VirutalDocumentRoot /var/www/localhost/%1/
</VirtualHost>

Make sure you enable Options +Indexes somwhere in your config (you can do that inside the VirtualHost containers) to get the index.html when no file is specified. And, of course, make sure you actually use VirtualHosts (= make sure you have a NameVirtualHost *:80 somewhere)