URL rewrite override in Drupal
Drupal 6 introduced a new automagical function for rewriting URLs output through most of Drupal called custom_url_rewrite_outbound().
The path module already gives you the ability to alias paths to different places, but only within the same domain. To redirect a path that has already been aliased, or to a different subdomain or different location altogether, adding custom_url_rewrite_outbound() to settings.php might be a solution for you. Since this is not a hook, it can only be used once per Drupal installation, which is part of why settings.php is a recommended place for it.
This code example will rewrite user, user/register, about, advertise, forum, and blog to other domains by changing the base_url by reference. Any URL on the site that passes through Drupal's core url() function will be rewritten, even if it was aliased by the path module.
<?php
function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
$url_rewrites = array(
// Drupal core paths
'user' => 'http://users.mysite.com',
'user/register' => 'http://users.mysite.com',
// general information paths
'about' => 'http://www.mysite.info',
'advertise' => 'http://www.mysite.info',
// other
'forum' => 'http://forums.mysite.com',
'blog' => 'http://blogs.mysite.com',
);
while (list($key, $value) = each($url_rewrites)) {
if ($path == $key || $original_path == $key) {
$options['base_url'] = $value; // updated by reference
$options['absolute'] = TRUE;
break;
}
}
}
?>
