FIX Escape the redirect URL before outputting (alternate implementation)

Slightly more rigorous implementation of #2981.

This PR would do well with a behat test, if someone has capacity to build one.

A manual test resulted in the following output.


```html
<p>Redirecting to <a href="http://www.google.com/#hello"
title="Click this link if your browser does not redirect you">
http://www.google.com/#hello... (output started on /sitedir/mysite/code/Page.php, line 47)</a></p>
<meta http-equiv="refresh" content="1; url=http://www.google.com/#hello" />
<script type="text/javascript">setTimeout(function(){ window.location.href = "http:\/\/www.google.com\/#hello"; }, 50);</script>
```