]> The LambCutlet Disorganisation » WordPress & non-absolute URIs fix

The LambCutlet Disorganisation

WordPress & non-absolute URIs fix

Posted by Jonathan at 22:07:09 UTC on the 25th of May, 2005

This little hack are for other WordPress users like myself whom enjoy cruft free linking as per RFC2396 and use:


<a href="/path/to/somewhere/">local link</a>

… or indeed:


<a href="//somedomain.tld/path/to/elsewhere/">external link</a>

… with abandon. Trouble is for users whom come to read your site via Atom feeds of whatever, such links will break. However, fear no more… as this the hack to fix this up is quite trivial.

Hunt down ./wp-includes/functions-formatting.php and find the function convert_chars(), looking for this:


	// Just a little XHTML help
	$content = str_replace('<br>', '<br />', $content);
	$content = str_replace('<hr>', '<hr />', $content);
	
	return $content;
}

… and replace with:


	// Just a little XHTML help
	$content = str_replace('<br>', '<br />', $content);
	$content = str_replace('<hr>', '<hr />', $content);
	
	// Sort out those absolute path & network location URIs
	$absolutist_uri_scheme = 'http'.(($_SERVER['HTTPS']=='on')?'s':'');
	$moral_relativism = array('/href=\"\/\//',
				'/href=\"\//');
	$total_absolutism = array('href="'.$absolutist_uri_scheme.'://',
				'href="'.$absolutist_uri_scheme.'://'.$_SERVER['HTTP_HOST'].'/');
	$content = preg_replace($moral_relativism, $total_absolutism, $content);
	
	return $content;
}

The hack should be HTTPS aware, for those of you hosting your blog on an SSL enabled site and all those damned morally relative tree-huggin’ hippy links shall get a good kick in the nuts and be blasted with draconian total absolutism, henceforth making Blogosphere™ a much better place for all, where no children will have to endure another 404! ;)

Filed under: Software

No Comments »

No comments yet.

RSS feed for comments on this post.

Leave a comment

Due to continued annoyance from spam-bots, this site now uses a Captcha. Disabled users can still submit their comments via my contact form.

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

Don't forget that this site support Gravatars!

(required)

(required)

Authorisation code image