diff --git a/domain_alias/domain_alias.admin.inc b/domain_alias/domain_alias.admin.inc
index ab119dd..b21cbcf 100755
--- a/domain_alias/domain_alias.admin.inc
+++ b/domain_alias/domain_alias.admin.inc
@@ -332,3 +332,158 @@ function domain_alias_help_text() {
     to the domain record for <em>example.com</em>. NOTE: <em>Only one wildcard is allowed per alias.</em></p>');
   return $output;
 }
+
+function domain_alias_patterns_form($form, &$form_state) {
+  $form['help'] = array(
+    '#markup' => domain_alias_help_text(),
+  );
+  $variables = array(
+    'items' => array(
+      '*.[hostname]',
+      '\2.example.com',
+      '\2.example.\1',
+      '?.[hostname]',
+      '[hostname]:*',
+    ),
+  );
+  $form['patterns'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Standard alias patterns when creating and updating domains.'),
+    '#rows' => 5,
+    '#cols' => 30,
+    '#default_value' => variable_get('domain_alias_patterns', NULL),
+    '#description' => t('Enter one pattern per line.  When creating or updating domains, an alias matching each pattern will be created.')
+      . domain_alias_patterns_help()
+      . '<p><em>' . t('Example patterns:') . '</em></p>'
+      . theme('item_list', $variables),
+  );
+  $form['update'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Create aliases for existing domains'),
+    '#description' => t('When submitting these changes, Domain Alias will create new aliases for all existing domains.'),
+    '#default_value' => 1,
+  );
+  $form['delete'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Delete aliases that do not match these patterns.'),
+    '#description' => t('Use with care. Recommended for expert users only.'),
+    '#default_value' => 0,
+  );
+  $form['actions']['test'] = array(
+    '#type' => 'submit',
+    '#value' => t('Test changes'),
+    '#submit' => array('domain_alias_patterns_test_submit'),
+  );
+  $form['actions']['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Save configuration'),
+    '#submit' => array('domain_alias_patterns_submit'),
+  );
+  return $form;
+}
+
+function domain_alias_patterns_help() {
+  $items = array();
+  foreach (domain_alias_pattern_list() as $key => $value) {
+    $items[] = t('<strong>!key</strong> !value', array('!key' => $key, '!value' => $value));
+  }
+  return '<p>' . t('The following replacements may be used in your alias patterns. Note that the order of numbered elements is right-to-left:')
+    . theme('item_list', array('items' => $items))
+    . t('Numbers up to 6 are allowed. Empty elements will be ignored.') . '</p>';
+}
+
+function domain_alias_pattern_list() {
+  return array(
+    '[hostname]' => t('The complete domain hostname, including a port, if provided. e.g. <em>example.com</em> or <em>foo.example.com:8080</em>.'),
+    '[port]' => t('The port identifier, if any. e.g. <em>8080</em>'),
+    '\1' => t('The first element of the domain. e.g. <em>com</em>.'),
+    '\2' => t('The second element of the domain. e.g. <em>example</em>.'),
+    '\3' => t('The third element of the domain, if present. e.g. <em>foo</em>.'),
+    '\4' => t('The fourth element of the domain, if present.'),
+  );
+}
+
+function domain_alias_patterns_form_validate($form, &$form_state) {
+  $patterns = $form_state['values']['patterns'];
+  $patterns = domain_alias_normalize_patterns($patterns);
+  foreach ($patterns as $pattern) {
+    $valid = domain_alias_valid_patterns();
+    $passed = FALSE;
+    foreach ($valid as $test) {
+      if ($test != '[hostname]' && $test != '[port]') {
+        if (substr_count($pattern, $test) > 0) {
+          $passed = TRUE;
+        }
+      }
+    }
+    if (!$passed && substr_count($pattern, '*') < 1 && substr_count($pattern, '?') < 1) {
+      form_set_error('patterns', t('Your patterns must each include at least one wildcard or token character.'));
+    }
+  }
+}
+
+function domain_alias_patterns_test_submit($form, &$form_state) {
+  $form_state['rebuild'] = TRUE;
+  $patterns = $form_state['values']['patterns'];
+  $aliases = domain_alias_build_patterns($patterns);
+  dsm($aliases);
+}
+
+function domain_alias_build_patterns($patterns) {
+  dsm($patterns);
+  $aliases = array();
+  $patterns = domain_alias_normalize_patterns($patterns);
+  dsm($patterns);
+  foreach ($patterns as $pattern) {
+    foreach (domain_domains() as $domain) {
+      $aliases[$pattern][] = domain_alias_pattern_replace($pattern, $domain);
+    }
+  }
+  return $aliases;
+}
+function domain_alias_normalize_patterns($patterns) {
+  $vars = preg_replace('/(\r\n|\n)/', "\r\n", $patterns);
+  $vars = explode("\r\n", $vars);
+  return $vars;
+}
+
+function domain_alias_pattern_replace($pattern, $domain) {
+  $find = domain_alias_valid_patterns();
+  $port = '';
+  $replace = array($domain['subdomain']);
+  $elements = explode(':', $domain['subdomain']);
+  if (isset($elements[1])) {
+    $port = array_pop($elements);
+  }
+  $replace[] = $port;
+  $items = array_reverse(explode('.', $elements[0]));
+  for ($i = 0; $i < 5; $i++) {
+    if (isset($items[$i])) {
+      $replace[] = $items[$i];
+    }
+    else {
+      $replace[] = '';
+    }
+  }
+  // Replace the strings.
+  $alias = str_replace($find, $replace, $pattern);
+  // Ensure we don't have multiple dots together.
+  $find = array('..', '...', '....', '.....');
+  $alias = trim(str_replace($find, '.', $alias));
+  // Prevent leading or trailing dot.
+  $alias = trim($alias, '.');
+  return $alias;
+}
+
+function domain_alias_valid_patterns() {
+  return array(
+    '[hostname]',
+    '[port]',
+    '\1',
+    '\2',
+    '\3',
+    '\4',
+    '\5',
+    '\6',
+  );
+}
diff --git a/domain_alias/domain_alias.module b/domain_alias/domain_alias.module
index 0447bf0..c20917c 100755
--- a/domain_alias/domain_alias.module
+++ b/domain_alias/domain_alias.module
@@ -80,6 +80,14 @@ function domain_alias_menu() {
     'page arguments' => array(4),
     'file' => 'domain_alias.admin.inc',
   );
+  $items['admin/structure/domain/alias'] = array(
+    'title' => 'Alias patterns',
+    'access arguments' => array('administer domains'),
+    'type' => MENU_LOCAL_TASK,
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('domain_alias_patterns_form'),
+    'file' => 'domain_alias.admin.inc',
+  );
   return $items;
 }
 
