diff -uprN domain-old\domain.admin.inc domain\domain.admin.inc
--- domain-old\domain.admin.inc	Sun Jun 08 18:24:14 2008
+++ domain\domain.admin.inc	Tue Jul 01 13:25:44 2008
@@ -62,6 +62,7 @@ function domain_view() {
     $link = l($domain['subdomain'], domain_get_uri($domain), array('absolute' => TRUE));
     if ($domain['domain_id'] == 0) {
       $actions = l(t('Default settings'), 'admin/build/domain/settings');
+      $actions .= ' | ' . l(t('Aliases'), 'admin/build/domain/alias/0');
       // Grab any extra elements defined by other modules.  If so, allow configuration.
       if (module_exists('domain_conf')) {
         $extra = array();
@@ -73,6 +74,7 @@ function domain_view() {
     }
     else {
       $actions = l(t('edit'), 'admin/build/domain/edit/'. $domain['domain_id']);
+      $actions .= ' | ' . l(t('Aliases'), 'admin/build/domain/alias/' . $domain['domain_id']);
       // Add advanced settings from other modules.
       $items = array();
       $items = module_invoke_all('domainlinks', $domain);
@@ -630,6 +632,7 @@ function domain_delete_form_submit($form
   // Run the lookup before we delete the row!
   $domain = domain_lookup($form_state['values']['domain_id']);
   db_query("DELETE FROM {domain} WHERE domain_id = %d", $form_state['values']['domain_id']);
+  db_query("DELETE FROM {domain_alias} WHERE domain_id = %d", $form_state['values']['domain_id']);
   // Let other modules act.
   module_invoke_all('domainupdate', 'delete', $domain, $form_state);
   // The user_submitted flag is needed for Domain User.
@@ -717,6 +720,163 @@ function domain_check_response($domain) 
     array('%server' => $url, '!code' => $response->code)), 'warning');
   }
 }
+
+/**
+ * Edit aliases
+ *
+ * @param $domain
+ *  The $domain object created by domain_lookup().
+ */
+function domain_alias($domain) {
+  if ($domain == -1) {
+    return t('Invalid page requested.');
+  }
+  // This action should be performed from the primary domain.
+  return drupal_get_form('domain_alias_form', $domain);
+}
+
+/**
+ * FormsAPI for editing domain aliases
+ *
+ * @param $form_state
+ * The current form state, passed by FormsAPI.
+ * @param $domain
+ * An array containing the record from the {domain} table.
+ * @param $arguments
+ *  An array of additional hidden key/value pairs to pass to the form.
+ *  Used by child modules to control behaviors.
+ */
+function domain_alias_form($form_state, $domain, $arguments = array()) {
+  $form = array();
+  // The $arguments arrray allows other modules to pass values to change the bahavior
+  // of submit and validate functions.
+  if (!empty($arguments)) {
+    $form['domain_arguments'] = array('#type' => 'value', '#value' => $arguments);
+  }
+
+  $form['domain_id'] = array('#type' => 'value', '#value' => $domain['domain_id']);
+  $record_edit_url = 'admin/build/domain/' . ($domain['domain_id'] == 0 ? '' : 'edit/'.$domain['domain_id']);
+  $form['domain'] = array(
+    '#type' => 'item',
+    '#title' => t('Main domain name for %title', array('%title' => $domain['sitename'])),
+    '#value' => $domain['subdomain'],
+    '#description' => t('Can be changed <a href="!url">here</a>.', array('!url' => url($record_edit_url))),
+  );
+
+  $form['domain_alias'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Edit domain aliases for @title', array('@title' => $domain['sitename'])),
+    '#collapsible' => TRUE,
+    '#tree' => TRUE,
+    '#description' => t('Defined aliases for this domain record, using the full
+      <em>path.example.com</em> format.  Can only contain lower-case alphanumeric characters. 
+      Leave off the http:// and the trailing slash.'),
+  );
+  
+  $count = 1;
+  if (isset($domain['aliases']) && is_array($domain['aliases'])) {
+    foreach( $domain['aliases'] as $alias_id => $alias){
+      $form['domain_alias'][$alias_id] = array(
+        '#type' => 'textfield',
+        '#default_value' => $alias['subdomain'] . ( $alias['pattern'] ? '|' . $alias['pattern'] : ''),
+        '#title' => 'Alias (#'.$alias_id.')',
+        '#maxlength' => 80,
+      );
+      $count++;
+    }
+  }
+
+  $form['domain_alias']['new1'] = array(
+    '#type' => 'textfield',
+    '#maxlength' => 80,
+    '#title' => 'New Aliases',
+  );
+  $form['domain_alias']['new2'] = array(
+    '#type' => 'textfield',
+    '#maxlength' => 80,
+ );
+  $form['domain_alias']['new3'] = array(
+    '#type' => 'textfield',
+    '#maxlength' => 80,
+    '#description' => t('<p><em>Advanced:</em> You can specify a pattern for your domains by
+      using % (percentage) to match any number of random characters and _ (underscore) to match only one random character. 
+      Please use a \'|\' character to separate the pattern from the domain name, example:
+      <strong>domain.com|%.example.com</strong> would match any subdomain of <em>example.com</em> onto this domain record.</p>
+      <p>If you need more fields just save the record, come back to this form and you will find three new empty fields. </p>'),
+  );
+
+  $form['submit'] = array('#type' => 'submit', '#value' => t('Save aliases'));
+  return $form;
+}
+
+/**
+ * FormsAPI for domain_alias_form()
+ */
+function domain_alias_form_validate($form, &$form_state) {
+  // validate aliases
+  $alias_dn = array();
+  foreach($form_state['values']['domain_alias'] as $id => $alias) {
+    if (!empty($alias)) {
+      list($_name,$_pattern) = explode('|', $alias);
+      $_name = strtolower(urlencode($_name));
+      
+      // 1. validate domain name
+      if (in_array($_name, $alias_dn)) {
+        form_set_error('domain_alias', t('The domain name must be unique.'));
+      }
+      else {
+        if (isset($form_state['values']['domain_id'])) {
+          $check = db_result(db_query("SELECT COUNT(alias_id) FROM {domain_alias} WHERE subdomain = '%s' AND domain_id <> %d", $_name, $form_state['values']['domain_id']));
+        } else {
+          $check = db_result(db_query("SELECT COUNT(alias_id) FROM {domain_alias} WHERE subdomain = '%s' ", $_name ));
+        }
+        
+        if ($check) {
+          form_error($form['domain_alias'][$id], t('The domain name %name is already being used by a different domain record.', array('%name' => $_name)));
+        }
+      }
+      $alias_dn[$id] = $_name;
+      
+      // 2. validate pattern
+      if (empty($_pattern)) {
+        $_pattern = '';
+      } else {
+        $c = preg_match('/^[a-z0-9.+\-%_]*$/', $_pattern);
+        if ($c == 0) {
+          form_error($form['domain_alias'][$id], t('The pattern %pat contains invalid characters. ', array('%pat' => $_pattern)));
+        }
+      }
+      $form_state['values']['domain_alias'][$id] = array('subdomain' => $_name, 'pattern' => $_pattern);
+    }
+  }
+}
+
+/**
+ * FormsAPI for domain_alias_form()
+ */
+function domain_alias_form_submit($form, &$form_state) {
+  foreach($form_state['values']['domain_alias'] as $id => $alias) {
+    // if not a new alias .. 
+    if (strpos($id, 'new') === FALSE) {
+      if (empty($alias['subdomain'])) {
+        // .. and alias empty -> delete
+        db_query("DELETE FROM {domain_alias} WHERE alias_id = %d", $id);
+      }
+      else {
+        // .. and alias not empty -> update
+        db_query("UPDATE {domain_alias} SET subdomain = '%s', pattern = '%s' WHERE alias_id = %d", $alias['subdomain'], $alias['pattern'], $id);
+      }
+    }
+    // if this is a new alias and it's not blank -> create new one
+    else if (!empty($alias['subdomain'])) {
+      db_query("INSERT INTO {domain_alias} (domain_id, subdomain, pattern) VALUES ('%d', '%s', '%s')", $form_state['values']['domain_id'], $alias['subdomain'], $alias['pattern']);
+    }
+  }
+  
+  drupal_set_message(t('Domain aliases updated.'));
+  $form_state['redirect'] = 'admin/build/domain/view';
+} 
+
 
 /**
  * Allows for the batch update of certain elements.
diff -uprN domain-old\domain.install domain\domain.install
--- domain-old\domain.install	Mon Apr 21 00:44:31 2008
+++ domain\domain.install	Tue Jul 01 11:13:51 2008
@@ -37,6 +37,16 @@ function domain_schema() {
     'indexes' => array(
       'nid' => array('nid')),
   );
+  $schema['domain_alias'] = array(
+    'fields' => array(
+      'alias_id' => array('type' => 'serial', 'not null' => TRUE),
+      'domain_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
+      'subdomain' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''),
+      'pattern' => array('type' => 'varchar', 'length' => '255', 'not null' => FALSE, 'default' => '')),
+    'primary key' => array('alias_id'),
+    'indexes' => array(
+      'subdomain' => array('subdomain', 'pattern')),
+  );
   return $schema;
 }
 
diff -uprN domain-old\domain.module domain\domain.module
--- domain-old\domain.module	Sun Jun 08 17:32:48 2008
+++ domain\domain.module	Tue Jul 01 13:36:54 2008
@@ -40,27 +40,37 @@ define('DOMAIN_SITE_GRANT', TRUE);
 function domain_init() {
   global $_domain, $conf;
   $_domain = array();
-  // Cribbed from bootstrap.inc -- removes port protocols from the host value.
-  $_subdomain = strtolower(implode('.', array_reverse(explode(':', rtrim($_SERVER['HTTP_HOST'], '.')))));
+  
+  // load bootstrap-file
+  require_once('./' . drupal_get_path('module', 'domain') . '/domain_bootstrap.inc');
+
+  $_subdomain = domain_current_domainname();
 
   // Strip the www. off the subdomain, if required by the module settings.
-  $raw_domain = $_subdomain;
-  if (variable_get('domain_www', 0)) {
+  if (variable_get('domain_www', 0) && ($www_replaced = strpos($_subdomain, 'www.')) !== FALSE) {
     $_subdomain = str_replace('www.', '', $_subdomain);
   }
   // Lookup the active domain against our allowed hosts record.
-  $data = db_fetch_array(db_query("SELECT domain_id FROM {domain} WHERE subdomain = '%s'", $_subdomain));
+  $domain_id = domain_resolve_host($_subdomain);
+     
   // Get the domain data.
-  $_domain = domain_lookup($data['domain_id']);
-
-  // If return is -1, then the DNS didn't match anything, so use defaults.
-  if ($_domain == -1) {
-    $_domain = domain_default();
+  $_domain = domain_lookup($domain_id);
+   
+  // If the domain record does not match the current domain name, load information on current {domain_alias}
+  if ($_subdomain != $_domain['subdomain']) {
+      $alias = domain_alias_lookup($_subdomain);
+      if (is_array($alias)) {
+        // if still not matching we're probably using pattern matching, so just use current domainname
+        if ($_subdomain != $alias['subdomain']) {
+          $alias['subdomain'] = $_subdomain;
+        }
+        $_domain = array_merge($_domain, $alias);
+        $_domain = domain_api($_domain);
+      }
   }
 
-  // If we stripped the www. send the user to the proper domain.  This should only
-  // happen once, on an inbound link or typed URL, so the overhead is acceptable.
-  if ($raw_domain != $_subdomain) {
+  // If we have replaced 'www.' in the url, redirect to the clean domain. 
+  if ($www_replaced !== FALSE) {  
     drupal_goto($_domain['path']);
   }
   
@@ -70,6 +80,7 @@ function domain_init() {
     $_domain = domain_default();
     drupal_goto($_domain['path']);
   }
+  
   // Set the site name to the domain-specific name.
   $conf['site_name'] = $_domain['sitename'];
 }
@@ -159,6 +170,14 @@ function domain_menu() {
     'page arguments' => array(4),
     'file' => 'domain.admin.inc',
   );
+  $items['admin/build/domain/alias/%domain'] = array(
+    'title' => 'Edit domain aliases',
+    'access arguments' => array('administer domains'),
+    'type' => MENU_CALLBACK,
+    'page callback' => 'domain_alias',
+    'page arguments' => array(4),
+    'file' => 'domain.admin.inc',
+  );
   return $items;
 }
 
@@ -440,6 +459,72 @@ function domain_lookup($domain_id = NULL
 }
 
 /**
+ * Runs a lookup against the {domain_alias} table.  One of the two values must be present
+ *
+ * This function also calls hook_domainload(), which lets module developers overwrite
+ * or add to the $domain array.
+ *
+ * @param $subdomain
+ *  The string representation of a {domain_alias} entry. Optional.
+ * @param $alias_id
+ *  The alias_id taken from {domain_alias}. Optional
+ * @param $reset
+ *  A boolean flag to clear the static variable if necessary.
+ * @return
+ *  An array containing the requested row from the {domain_alias} table.
+ *  Returns -1 on failure.
+ */
+function domain_alias_lookup($subdomain = NULL, $alias_id = NULL, $reset = FALSE ){
+  static $aliases;
+  // If both are NULL, no lookup can be run.
+  if (is_null($subdomain) && is_null($alias_id)) {
+    return -1;
+  }
+  // Create a unique key so we can static cache all requests.
+  $key = $alias_id . '_' . $subdomain;
+  
+  // Run the lookup, if needed.
+  if (!isset($aliases[$key]) || $reset) {
+    if (is_string($subdomain)) {
+      $alias = db_fetch_array(db_query_range("SELECT alias_id, domain_id, subdomain, pattern FROM {domain_alias} ".
+        "WHERE subdomain = '%s' OR '%s' LIKE (pattern)", $subdomain, $subdomain, 0, 1));
+    }
+    else if (intval($alias_id)) {
+      $alias = db_fetch_array(db_query("SELECT alias_id, domain_id, subdomain, pattern FROM {domain_alias} WHERE alias_id = %d", $alias_id));
+    }
+    if (isset($alias['alias_id'])) {
+      $aliases[$key] = $alias;
+      $aliases[$alias['alias_id'].'_'] =& $aliases[$key]; 
+    } else {
+      $aliases[$key] = -1;
+    }
+  }
+  return $aliases[$key];
+}
+
+/**
+ * Return all aliases for one domain (record)
+ *
+ * @param $domain_id
+ *  The domain_id taken from {domain}.
+ * @param $reset
+ *  A boolean flag indicating whether to reset the static array or not.
+ * @return
+ *  An array of all aliases defined for given domain_id, indexed by alias_id
+ */
+function domain_aliases($domain_id, $reset = FALSE) {
+  static $aliases = array();
+  if (!isset($aliases[$domain_id]) || $reset) {
+    // Query the db for aliases
+    $result = db_query("SELECT alias_id FROM {domain_alias} WHERE domain_id = %d", $domain_id);
+    while ($data = db_fetch_array($result)) {
+      $aliases[$domain_id][$data['alias_id']] = domain_alias_lookup(NULL, $data['alias_id']);
+    }
+  }
+  return $aliases[$domain_id];
+}
+
+/**
  * Assigns the default settings to domain 0, the root domain.
  *
  * This value is used throughout the modules, so needed abstraction.
@@ -558,6 +643,8 @@ function domain_api($domain) {
  * Adds the home page 'path' and 'site_grant' boolean.
  */
 function domain_domainload(&$domain) {
+  // Get the domain aliases
+  $domain['aliases'] = domain_aliases($domain['domain_id']);
   // Get the path to the home page for this domain.
   $domain['path'] = domain_get_path($domain);
   // Grant access to all affiliates.
diff -uprN domain-old\domain_bootstrap.inc domain\domain_bootstrap.inc
--- domain-old\domain_bootstrap.inc	Thu Jan 01 01:00:00 1970
+++ domain\domain_bootstrap.inc	Tue Jul 01 00:14:34 2008
@@ -0,0 +1,77 @@
+<?php 
+// $Id$
+/**
+ * 
+ * @file Domain bootstrap file
+ * 
+ * Functions for determining and resolving the current domainname...
+ *   
+ * Used by domain_init(), _domain_prefix_load(), _domain_conf_load()
+ * 
+ * @ingroup domain
+ */
+
+// make sure database is loaded
+_drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
+
+/**
+ * Tries to match the current (host) domainname to a domain in the {domain}
+ * table and return a respective domain_id
+ * 
+ * @param  $_domainname
+ *  The domainname to match against. Optional.
+ * 
+ * @return
+ *  A domain_id matching the current domainname
+ */
+function domain_resolve_host($_domainname = FALSE) {
+  if (empty($_domainname)) {
+    $_domainname = domain_current_domainname();
+  }
+  
+  return _domain_lookup_simple($_domainname);
+} 
+
+/**
+ * Runs a lookup against the {domain} and {domain_alias} tables.  
+ * 
+ * @param $domainname
+ *  The string representation of a {domain} entry.
+ * @param  $reset
+ *  Set TRUE to ignore cached versions and look the name up again. Optional.
+ * 
+ * @return
+ *  A domain_id from {domain} matching the given domainname or -1 if none found. 
+ */
+function _domain_lookup_simple($_domainname, $reset = FALSE){
+  static $cache = array();
+
+  if (empty($_domainname)) return 0;
+  
+  if ($reset || !isset($cache[$_domainname])) {
+    // Lookup the given domainname against our allowed hosts record.
+    $domain = db_fetch_array(db_query_range("SELECT domain_id FROM domain WHERE subdomain = '%s' ".
+      "UNION SELECT domain_id FROM domain_alias WHERE subdomain = '%s' OR '%s' LIKE (pattern)",
+      $_domainname, $_domainname, $_domainname, 0, 1));
+      
+    // no match => use default (0)
+    if (!isset($domain['domain_id'])) {
+      $domain = array('domain_id' => 0);
+    }
+    
+    $cache[$_domainname] = $domain['domain_id'];
+  }
+  return $cache[$_domainname];
+}
+
+/**
+ * Determine current fully qualified domainname
+ * 
+ * @return
+ *  (String) The current (host) domainname
+ */
+function domain_current_domainname() {
+  // We lower case this, since EXAMPLE.com == example.com.
+  return strtolower(rtrim($_SERVER['HTTP_HOST']));
+} 
+
diff -uprN domain-old\domain_conf\domain_conf.admin.inc domain\domain_conf\domain_conf.admin.inc
--- domain-old\domain_conf\domain_conf.admin.inc	Sun Mar 30 19:51:46 2008
+++ domain\domain_conf\domain_conf.admin.inc	Wed Jun 25 16:41:42 2008
@@ -276,3 +276,144 @@ function theme_domain_conf_reset($domain
   }
   return $output;
 }
+
+
+/**
+ * The domain menu page callback router.
+ *
+ * @param $domain_id
+ *  The unique identifier for this domain, taken from {domain}.
+ *
+ * @ingroup menu
+ */
+function domain_menu_page($domain_id = NULL) {
+  global $_domain;
+  if($domain_id == NULL) {
+  	  $domain = $_domain;
+  }
+  else {
+      $domain = domain_lookup($domain_id);
+  }
+  if ($domain['domain_id']) {
+    // Ensure we are on the proper domain.
+    domain_goto($domain);
+    drupal_set_title(t('!site : Domain menu settings', array('!site' => $domain['sitename'])));
+
+    $output = '<p>'. t('These settings will replace or supplement your default menu settings when %name is the active domain.', array('%name' => $domain['sitename'])) .'</p>';
+    // Leave this for now even though we are not using a form_alter
+    return drupal_get_form('domain_menu_form',$domain);
+  }
+  else {
+    return t('Invalid domain request.');
+  }
+}
+
+/**
+ * Menu callback; presents menu configuration options - per domain.
+ * See domain_menu.module.
+ *
+ * Function scraped from menu modules menu_configure()
+ */
+function domain_menu_form($domain) {
+  global $_domain;
+  $domain_id=$_domain['domain_id'];
+  if (!is_null($domain_id)) {
+    $return = db_fetch_array(db_query("SELECT domain_id, menu_settings FROM {domain_conf} WHERE domain_id = %d", $domain_id));
+  }
+
+  if (!empty($return)) {
+    $return = unserialize($return['menu_settings']);
+  }else {
+    $return = -1;
+  }
+
+  $domain_menus = $return;
+
+  // Find All memu items excluding the "Navigation" menu
+  $root_menus = menu_get_menus();
+  $primary_options = $root_menus;
+
+  //trace($primary_options);
+  $primary_options[0] = t('No primary links');
+
+  $form['domain_settings_links'] = array('#type' => 'fieldset',
+    '#title' => t('Primary and secondary links settings'),
+  );
+
+  $form['domain_settings_links']['intro'] = array('#type' => 'item',
+    '#value' => t('Primary and secondary links provide a navigational menu system which usually (depending on your theme) appears at the top-right of the browser window. The links displayed can be generated either from a custom list created via the <a href="@menu">menu administration</a> page or from a built-in list of menu items such as the navigation menu links.', array('@menu' => url('admin/build/menu'))),
+  );
+
+  $form['domain_settings_links']['menu_primary_menu'] = array('#type' => 'select',
+    '#title' => t('Menu containing primary links'),
+    '#default_value' => $domain_menus['menu_primary_links_source'] ? $domain_menus['menu_primary_links_source'] : 0,
+    '#options' => $primary_options,
+  );
+
+  $secondary_options = $root_menus;
+  $secondary_options[0] = t('No secondary links');
+
+  $form['domain_settings_links']['menu_secondary_menu'] = array('#type' => 'select',
+    '#title' => t('Menu containing secondary links'),
+    '#default_value' => $domain_menus['menu_secondary_links_source'] ? $domain_menus['menu_secondary_links_source'] : 0,
+    '#options' => $secondary_options,
+    '#description' => t('If you select the same menu as primary links then secondary links will display the appropriate second level of your navigation hierarchy.'),
+  );
+
+  $form['domain_settings_authoring'] = array('#type' => 'fieldset',
+    '#title' => t('Content authoring form settings'),
+  );
+
+  $form['domain_settings_authoring']['intro'] = array('#type' => 'item',
+    '#value' => t('The menu module allows on-the-fly creation of menu links in the content authoring forms. The following option limits the menus in which a new link may be added. E.g., this can be used to force new menu items to be created in the primary links menu or to hide admin menu items.'),
+  );
+
+  $authoring_options = $root_menus;
+  $authoring_options[0] = t('Show all menus');
+
+  $form['domain_settings_authoring']['menu_parent_items'] = array('#type' => 'select',
+    '#title' => t('Restrict parent items to'),
+    '#default_value' => $domain_menus['menu_default_node_menu'] ? $domain_menus['menu_default_node_menu'] : 0,
+    '#options' => $authoring_options,
+    '#description' => t('Choose the menu to be made available in the content authoring form. Only this menu item and its children will be shown.'),
+   );
+
+  // Which domain are we editing?
+  $form['domain_id'] = array(
+    '#type' => 'value',
+    '#value' => $_domain['domain_id'],
+  );
+
+  // Our submit handlers.
+
+  $form['#submit'][] = 'domain_menu_submit';
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Save configuration'),
+  );
+  return $form;
+}
+
+function domain_menu_submit($form, &$form_state) {
+  $form_values = $form_state['values'];
+  $id = $form_values['domain_id'];
+
+  $menus = array();
+  $menus['menu_primary_links_source'] = $form_values['menu_primary_menu'];
+  $menus['menu_secondary_links_source'] = $form_values['menu_secondary_menu'];
+  $menus['menu_default_node_menu'] = $form_values['menu_parent_items']; // temp
+
+  $menus = serialize($menus);
+  $check = 0;
+  $check = db_result(db_query("SELECT COUNT(domain_id) FROM {domain_conf} WHERE domain_id = %d", $id));
+
+  if ($check <= 0) {
+    db_query("INSERT INTO {domain_conf} (domain_id, menu_settings) VALUES (%d, '%s')", $id, $menus);
+  }
+  else {
+    db_query("UPDATE {domain_conf} SET menu_settings = '%s' WHERE domain_id = %d", $menus, $id);
+  }
+
+  drupal_set_message(t('Domain menu options saved successfully.'));
+}
+
diff -uprN domain-old\domain_conf\domain_conf.module domain\domain_conf\domain_conf.module
--- domain-old\domain_conf\domain_conf.module	Sun Jun 08 17:12:38 2008
+++ domain\domain_conf\domain_conf.module	Tue Jul 01 13:39:54 2008
@@ -50,7 +50,7 @@ function domain_conf_menu() {
     'page callback' => 'domain_conf_reset',
     'page arguments' => array(4),
     'file' => 'domain_conf.admin.inc',
-  );
+  );	
   return $items;
 }
 
diff -uprN domain-old\domain_conf\settings_domain_conf.inc domain\domain_conf\settings_domain_conf.inc
--- domain-old\domain_conf\settings_domain_conf.inc	Sun Jun 08 17:32:48 2008
+++ domain\domain_conf\settings_domain_conf.inc	Tue Jul 01 13:28:18 2008
@@ -19,7 +19,7 @@
  * @ingroup domain_conf
  */
 
-_drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
+require_once(dirname(dirname(__FILE__)) . '/domain_bootstrap.inc');
 _domain_conf_load();
 
 /**
@@ -30,15 +30,11 @@ _domain_conf_load();
 function _domain_conf_load($domain = NULL) {
   $check = db_result(db_query("SELECT status FROM {system} WHERE name = 'domain_conf'"));
   if ($check > 0) {
-    if (is_null($domain)) {
-      // Cribbed from bootstrap.inc -- removes port protocols from the host value.
-      $_subdomain = strtolower(implode('.', array_reverse(explode(':', rtrim($_SERVER['HTTP_HOST'], '.')))));
-      // Lookup the active domain against our allowed hosts record.
-      $domain = db_fetch_array(db_query("SELECT domain_id FROM {domain} WHERE subdomain = '%s'", $_subdomain));
+    if (isset($domain['domain_id'])) {
+      $domain_id = $domain['domain_id'];
     }
-    // If nothing was found, use the default domain.
-    if (!isset($domain['domain_id'])) {
-      $domain['domain_id'] = 0;
+    else {
+      $domain_id = domain_resolve_host();
     }
     $data = array();
     $data = db_fetch_array(db_query("SELECT settings FROM {domain_conf} WHERE domain_id = %d", $domain['domain_id']));
diff -uprN domain-old\domain_prefix\settings_domain_prefix.inc domain\domain_prefix\settings_domain_prefix.inc
--- domain-old\domain_prefix\settings_domain_prefix.inc	Sun Jun 08 17:32:48 2008
+++ domain\domain_prefix\settings_domain_prefix.inc	Tue Jul 01 13:28:57 2008
@@ -10,7 +10,7 @@
  * @ingroup domain_prefix
  */
 
-_drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
+require_once(dirname(dirname(__FILE__)) . '/domain_bootstrap.inc');
 _domain_prefix_load();
 
 /**
@@ -21,32 +21,30 @@ _domain_prefix_load();
 function _domain_prefix_load($domain = NULL) {
   $check = db_result(db_query("SELECT status FROM {system} WHERE name = '%s'", 'domain_prefix'));
   if ($check > 0) {
-    if (is_null($domain)) {
-      // Cribbed from bootstrap.inc -- removes port protocols from the host value.
-      $_subdomain = strtolower(implode('.', array_reverse(explode(':', rtrim($_SERVER['HTTP_HOST'], '.')))));
-      // Lookup the active domain against our allowed hosts record.
-      $domain = db_fetch_array(db_query("SELECT domain_id FROM {domain} WHERE subdomain = '%s'", $_subdomain));
-    }
     if (isset($domain['domain_id'])) {
-      $tables = array();
-      $prefix = 'domain_'. $domain['domain_id'] .'_';
-      $result = db_query("SELECT tablename FROM {domain_prefix} WHERE domain_id = %d AND status > %d", $domain['domain_id'], 1);
-      while ($data = db_fetch_array($result)) {
-        $tables[] = $data['tablename'];
+      $domain_id = $domain['domain_id'];
+    }
+    else {
+      $domain_id = domain_resolve_host();
+    }
+    $tables = array();
+    $prefix = 'domain_'. $domain_id .'_';
+    $result = db_query("SELECT tablename FROM {domain_prefix} WHERE domain_id = %d AND status > %d", $domain_id, 1);
+    while ($data = db_fetch_array($result)) {
+      $tables[] = $data['tablename'];
+    }
+    if (!empty($tables)) {
+    global $db_prefix;
+      $new_prefix = array();
+      // There might be global prefixing; if so, prepend the global.
+      if (is_string($db_prefix)) {
+        $new_prefix['default'] = $db_prefix;
+        $prefix = $db_prefix . $prefix;
       }
-      if (!empty($tables)) {
-        global $db_prefix;
-        $new_prefix = array();
-        // There might be global prefixing; if so, prepend the global.
-        if (is_string($db_prefix)) {
-          $new_prefix['default'] = $db_prefix;
-          $prefix = $db_prefix . $prefix;
-        }
-        foreach ($tables as $table) {
-          $new_prefix[$table] = $prefix;
-        }
-        $db_prefix = $new_prefix;
+      foreach ($tables as $table) {
+        $new_prefix[$table] = $prefix;
       }
+      $db_prefix = $new_prefix;
     }
   }
 }
