Index: API.php
===================================================================
RCS file: /cvs/drupal/contributions/modules/domain/API.php,v
retrieving revision 1.23.2.9
diff -u -r1.23.2.9 API.php
--- API.php	25 Jul 2008 18:07:14 -0000	1.23.2.9
+++ API.php	11 Sep 2008 02:21:38 -0000
@@ -478,3 +478,18 @@
   // User login should always be from the current domain.
   return array('user_login');
 }
+
+/**
+ * Allows modules to alter path when rewriting URLs
+ *
+ * @param $domain_id
+ *  The domain_id taken from {domain}.
+ * @param $path
+ *  The internal drupal path to the node.
+ *
+ * @ingroup domain_hooks
+ */
+function hook_domainpath($domain_id, &$path) {
+  // Give a normal path alias
+  $path = drupal_get_path_alias($path);
+}
Index: domain.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/domain/domain.module,v
retrieving revision 1.40.2.22
diff -u -r1.40.2.22 domain.module
--- domain.module	9 Sep 2008 15:34:49 -0000	1.40.2.22
+++ domain.module	11 Sep 2008 02:19:40 -0000
@@ -591,7 +591,15 @@
  * Determine an absolute path to the current page
  */
 function domain_get_uri($domain) {
-  $path = $domain['scheme'] .'://'. $domain['subdomain'] . request_uri();
+  $request_uri = request_uri();
+
+  // Let modules modify path alias
+  $alias = substr($request_uri, strlen(base_path()));
+  $path = drupal_get_normal_path($alias);
+  $alias = domain_path($domain['domain_id'], $path);
+  $request_uri = base_path() . $alias;
+
+  $path = $domain['scheme'] .'://'. $domain['subdomain'] . $request_uri;
   return $path;
 }
 
@@ -1433,3 +1441,28 @@
   }
   return $return;
 }
+
+/**
+ * Helper function for passing hook_domainpath() by reference.
+ *
+ * @param $domain_id
+ * The domain_id taken from {domain}.
+ * @param $path
+ * The internal drupal path to the node.
+ * @return
+ * The $path, modified by reference by hook_domainpath() implementations.
+ */
+function domain_path($domain_id, $path) {
+  static $_modules;
+  if (!isset($_modules)) {
+    $_modules = module_implements('domainpath');
+  }
+  if (!empty($_modules)) {
+    foreach ($_modules as $module) {
+      // Cannot use module_invoke_all() since these are passed by reference.
+      $function = $module .'_domainpath';
+      $function($domain_id, $path);
+    }
+  }
+  return $path;
+}
Index: settings_custom_url.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/domain/settings_custom_url.inc,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 settings_custom_url.inc
--- settings_custom_url.inc	25 Jul 2008 17:50:45 -0000	1.1.2.3
+++ settings_custom_url.inc	11 Sep 2008 02:17:43 -0000
@@ -92,14 +92,16 @@
             if (isset($source)) {
               $seo = FALSE;
             }
+            $path = domain_path($domain[$nid]['domain_id'], $original_path);
           }
         }
         // If strict SEO rules are enabled, we set "all affiliate" links to the root domain.
         // Only needed if we are not on the default source domain.
         else if ($seo && $_domain['domain_id'] != $root['domain_id']) {
           $absolute = TRUE;
-            // In this case, the $base_url cannot have a trailing slash
-            $base_url = rtrim($root['path'], '/');
+          // In this case, the $base_url cannot have a trailing slash
+          $base_url = rtrim($root['path'], '/');
+          $path = domain_path($root['domain_id'], $original_path);
         }
       }
     }
Index: domain_prefix/domain_prefix.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/domain/domain_prefix/domain_prefix.module,v
retrieving revision 1.12.2.3
diff -u -r1.12.2.3 domain_prefix.module
--- domain_prefix/domain_prefix.module	4 Jul 2008 19:21:01 -0000	1.12.2.3
+++ domain_prefix/domain_prefix.module	11 Sep 2008 05:40:41 -0000
@@ -783,3 +783,41 @@
     drupal_set_message(t('The Domain Prefix module is not installed correctly.  Please edit your settings.php file as described in <a href="!url">INSTALL.txt</a>', array('!url' => base_path() . drupal_get_path('module', 'domain_prefix') .'/INSTALL.txt')));
   }
 }
+
+
+/**
+ * Implements hook_domainpath()
+ */
+function domain_prefix_domainpath($domain_id, &$path) {
+  // $map[$domain_id] keys are Drupal paths and the values are the corresponding aliases
+  static $map = array(), $count = array();
+  static $status = array();
+  $tablename = 'url_alias';
+
+  if (!isset($status[$domain_id])) {
+    $status[$domain_id] = db_result(db_query("SELECT status FROM {domain_prefix} WHERE domain_id = %d AND tablename = '%s'", $domain_id, $tablename));
+
+    // Table creation sequence has not run for this domain or the domain is primary domain.
+    if (!$status[$domain_id]) {
+      $status[$domain_id] = DOMAIN_PREFIX_IGNORE;
+    }
+  }
+
+  // If the url_alias table is prefixed, get the prefixed table name.
+  if ($status[$domain_id] > DOMAIN_PREFIX_IGNORE) {
+    $tablename = domain_prefix_string($domain_id) . $tablename;
+  }
+
+  // Use $count[$domain_id] to avoid looking up paths in subsequent calls if there simply are no aliases
+  if (!isset($count[$domain_id])) {
+    $count[$domain_id] = db_result(db_query('SELECT COUNT(pid) FROM {%s}', $tablename));
+  }
+  
+  if ($count[$domain_id] > 0 && $path != '') {
+    if (!isset($map[$domain_id][$path])) {
+      $alias = db_result(db_query("SELECT dst FROM {%s} WHERE src = '%s'", $tablename, $path));
+      $map[$domain_id][$path] = $alias ? $alias : $path;
+    }
+    $path = $map[$domain_id][$path];
+  }
+}

