Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.750
diff -u -4 -p -r1.750 common.inc
--- includes/common.inc	10 Jan 2008 23:14:58 -0000	1.750
+++ includes/common.inc	17 Jan 2008 14:39:41 -0000
@@ -1313,9 +1313,8 @@ function url($path = NULL, $options = ar
   if (!isset($options['base_url'])) {
     // The base_url might be rewritten from the language rewrite in domain mode.
     $options['base_url'] = $base_url;
   }
-  $base = $options['absolute'] ? $options['base_url'] .'/' : base_path();
 
   // Preserve the original path before aliasing.
   $original_path = $path;
 
@@ -1323,19 +1322,24 @@ function url($path = NULL, $options = ar
   if (!empty($path) && $path != '<front>') {
     if (!$options['alias']) {
       $path = drupal_get_path_alias($path, isset($options['language']) ? $options['language']->language : '');
     }
-    if (function_exists('custom_url_rewrite_outbound')) {
-      // Modules may alter outbound links by reference.
-      custom_url_rewrite_outbound($path, $options, $original_path);
-    }
-    $path = drupal_urlencode($options['prefix'] . $path);
+    $prefix = $options['prefix'];
   }
   else {
     // Will be empty if there is no language prefix.
-    $path = trim($options['prefix'], '/');
+    $prefix = trim($options['prefix'], '/');
+    $path = '';
+  }
+
+  if (function_exists('custom_url_rewrite_outbound')) {
+    // Modules may alter outbound links by reference.
+    custom_url_rewrite_outbound($path, $options, $original_path);
   }
 
+  $base = $options['absolute'] ? $options['base_url'] .'/' : base_path();
+  $path = drupal_urlencode($prefix . $path);
+
   if ($clean_url) {
     // With Clean URLs.
     if ($options['query']) {
       return $base . $path .'?'. $options['query'] . $options['fragment'];
