Your Ad Here

Apache – Alias Configuration with ServerAlias

December 13, 2007

What is Alias?

Alias is an alternative name to delivery a domain name. For example we have www.smokinglinux.com domain name configured correctly in our apache configuration files and we want other domains linking directly on our master domain or subdomains linking on www.smokinglinux.com. To know better this tutorial you have to see a configuration sample attached below:

NameVirtualHost 127.0.0.1:80

<VirtualHost 127.0.0.1:80>
ServerName www.smokinglinux.com
ServerAlias smokinglinux.com web.smokinglinux.com
DocumentRoot /var/www/smokinglinux.com
</VirtualHost>

How we can see in attached configuration code, we have a virtualhost code container with a ServerName and ServerAlias. ServerName is the main domain and ServerAlias is a set of alternatives names for main domain. In this case, when we try to reach this virtualhost by a browser, we can use “www.smokinglinux.com”, “smokinglinux.com” and “web.smokinglinux.com” to see the same website for every of these domain names.

Suppose that we want every possible subdomains linking on main domain “www.smokinglinux.com”. How we can configure it? Simply replacing with “*” before domain name on ServerAlias. For example:

ServerAlias *.smokinglinux.com

To make your Alias configuration working, you have to configure correctly your domain DNS. In fact, if you want a subdomain as ServerAlias, you must configure DNS with A record pointing on IP of main domain name.

To write apache configuration files you can edit httpd.conf or for new versions of apache, you can create a new file under ./site-available and then by shell: “a2ensite filename”, to enable configuration file under apache. You must reload Apache configuration file after every change. On Debian and Ubuntu you can run: “/etc/init.d/apache2 reload”.

Managed Colocation

Shared Hosting Special: Free setup & 2nd month free. Promo code 7395.

Dedicated Servers

20% off all Managed Servers includes free setup!

Related Post