As @Tomalak says, you should not be using javascript to solve this problem. Use a server redirect.
However, there is a more general problem with getting php data into javascript. I'll solve that problem here.
You need to escape the $url parameter properly for both javascript AND html. redirect() is not defined because there's a syntax error in it.
Whenever you need to pass javascript data inline into html, use the following pattern. It is the clearest, safest way to do this.
<?php
// 1. put all the data you want into a single object
$data = compact($url);
// $data === array('url'=>'http://example.org')
// 2. Convert that object to json
$jsdata = json_encode($url);
// 3. html-escape it for inclusion in a script tag
$escjsdata = htmlspecialchars($jsdata, ENT_NOQUOTES, 'utf-8');
// change utf-8 to whatever encoding you are using in your html.'
// I hope for your sanity you are using utf-8!
// 4. Now assign $escjsdata to a js variable in your html:
?>
<html>
<head>
<title>Redirecting</title>
</head>
<body onload='redirect()'>
Not Logged In
<script type = 'text/javascript'>
function redirect() {
var data = <?php echo $escjsdata ?>;
window.location=data.url;
}
</script>
</body>
</html>