PHP header redirect not working


To redirect pages SEO friendly, can a PHP 301 Redirect machen_

header("Location: http://www. new-location.de/foo_new.php",true,301);
exit;

I had also the problem, that no error message “Header already sent” was issued, to figure, why the command is not working. The fact is, that the header() Command only, If no screen output has been. This also affects Spaces, as often occur in PHP files at the beginning or end of the source code:

_<?php

or

?>_

To find these sites, you should insert the following code before the redirect, if no error message “header already sent in line”gets:

    if(headers_sent($file, $line)){
        echo "Headers already sent in $file on line $line";
    }