syntax error on nonexistent page

Permalink
Greetings! If I navigate to a page which does not exist, e.g. /asdfasdf/ I receive an error from the first routine in my code. Why doesn't the object exist if the page is invalid? Is there a way to test for this?

Fatal error: Call to a member function getCollectionAttributeValue() on a non-object in header.php on line 7

<head>
<?php
if ($redirectURL = $c->getCollectionAttributeValue('redirect_url')) {
   if ($redirectURL != '') {
      Header( "HTTP/1.1 301 Moved Permanently" );
      Header( "Location: " . $redirectURL );
   }
}
?>

Nirgali