Would be possible with php and one regular expression to do the following. Get all hyperlinks inside of a content and rewrite them if the top level domain of hyperlink is matching a given tld name from array.
Now have a regular expression which rewrites all hyperlinks in a given content
preg_replace('/<a(.*)href="([^"]*)"(.*)>/','<a$1href="goto.php?url=$2"$3>', $content);
example
$tld = array("http://www.example.com","http://www.test.com");
if <a href="www.example.com">example</a> than <a href="/goto.php?url= www.example.com"</a>;