Apache Virtual Host Example

There are so many variation of how to setup Apache VirtualHost that its difficult for a beginner to figure it all out.

Here is how I have found works best for a LAMP server that you own. If its not a standard Linux distro (Debian/Ubuntu here) all bets are off.

sudo vi /etc/apache2/sites-available/www.example.com

copy this code into the file

<VirtualHost *:80>
     ServerAdmin webmaster@example.com
     ServerName www.example.com
     ServerAlias example.com
     DocumentRoot /var/www/www.example.com/
</VirtualHost>

if you have a sub directory that also has a site

<VirtualHost *:80>
     ServerAdmin webmaster@example.com
     ServerName www.example.de/en
     ServerAlias example.de/en
     Redirect http://example.de/en/ http://www.example.de/en/
     DocumentRoot /var/www/www.example.de/en/

     ServerName www.example.de
     ServerAlias example.de
     Redirect http://example.de/ http://www.example.de/
     DocumentRoot /var/www/www.example.de/
</VirtualHost>

For a broader description of setting up Apache for virtual hosting

You may also like...