How to configure site aliases and domain redirection on Aegir

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
You are viewing a wiki page. You are welcome to join the group and then edit it. Be bold!

Introduction

Site aliases are helpful if you move content to a new domain, change domain names or simply want to make sure that http://example.com and http://www.example.com take users to the same place. You can implement site aliases with or without redirection. The differences between these two methods and how Aegir handles them is described below.

Enable Alias Support in Aegir

  1. You have to enable alias support in Aegir as it is off by default. Assuming the URL of your Aegir front end is aegir.example.com, browse to aegir.example.com/admin/hosting/features
    how to get to the Aegir features page

  2. Check the Site aliasing box
    how to enable site aliasing on Aegir

  3. Click Save configuration

Global Settings for Aliasing

After you have enabled the site aliasing feature in Aegir you can navigate to aegir.example.com/admin/hosting/aliases (see the menu item that is added under Hosting in the admin menu bar). Here you can set default site alias settings for all of your Aegir-hosted sites.

global site aliasing settings

Site-Specific Settings for Aliasing

You can override the global settings for aliasing by configuring site-specific alias settings either when you create the site or later by editing the site settings.

site-specific aliasing settings

NOTE: The current Version of Aegir (0.4 release) hides this form input.
Line 52 of /profiles/hostmaster/modules/hosting/alias/hosting_alias.module

    $form['redirection'] = array(
      '#type' => 'hidden',
      '#title' => t('Redirect domain aliases to main domain'),
      '#default_value' => isset($form['#node']->redirection) ? $form['#node']->redirection : variable_get('hosting_alias_redirection', FALSE),
      '#weight' => 11,
    );

Redirection Option

For users, one of the main differences that occurs when redirection is turned on is that the URL that they enter in the browser address bar changes. This reflects what the server is doing, which is in effect to redirect the request to the same site under the main URL, as opposed to serving the same site from under an alias.

User navigates to my-old-domain.com with redirection off

aliasing without redirection

User navigates to my-old-domain.com with redirection on

aliasing with redirection

Aegir alias management under the hood

Aegir primarily manages aliases in the virtual hosts file for each site (e.g. /var/aegir/config/server_master/apache/vhost.d/www.example.com)

When Aliases are in use, the virtual hosts file will have a ServerAlias directive for each site alias:

ServerAlias example.com
ServerAlias www.my-old-domain.com

Note: The following applies to Drupal 6 sites specifically! The functionality described has been replaced by the $sites array in sites.php for Drupal 7.
In addition to the above directives, when redirection is off, Aegir creates a symlink in the platform/sites/ folder for each alias that points to the folder associated with the primary domain

lrwxrwxrwx 1 aegir aegir   15 Oct 31 23:25 example.com -> www.example.com
drwxr-xr-x 7 aegir aegir 4096 Oct 31 23:02 www.example.com
lrwxrwxrwx 1 aegir aegir   15 Oct 31 23:25 www.my-old-domain.com -> www.example.com

When redirection is enabled, Rewrite directives are added to the virtualhost to send http requests to the primary domain that the aliases are associated with:

ServerAlias example.com
ServerAlias www.my-old-domain.com
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^/(.)$ http://www.example.com/$1 [L,R=301]

The symlinks are not required in this case.

Aegir hosting system

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week