Rendering External URL Aliases as External Links
Drupal 6 doesn't seem to mind if you save an external URL as a node's path alias. Rendering it, however, throws the full, escaped URL as a path within the site. For some reason (I'm guessing .htaccess), those links still end up going to the external URL, but they look most ugly, and don't trigger External Links processing.
So, the key is the custom_url_rewrite_outbound function. This weird, quasi-hook of a function can be placed in settings.php to affect the behavior of links generated by url(). As noted in that documentation, url() may be called dozens of times in a single page request, so performance is extremely crucial here.
<?php
function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
if (strpos($path, 'http:') === 0 && strpos($original_path, 'node/') === 0) {
$options['absolute'] = TRUE;
$options['base_url'] = filter_xss_bad_protocol($path, FALSE);
$path = '';
}
}
?>We detect if we're looking at an external URL as an alias for a node. If so, we set the base url for this link to the alias, and just wipe out the old path. url()'s processing will take care of the rest. http: detection will take care of nearly all links on the site I'm working with and anything more complex (multiple protocols) would be a performance hit.


