Jump to content

http 301 redirect not working (seo friendly redirect in php)

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
jimiwa

jimiwa

    Newbie

  • Members
  • PipPip
  • 14 posts
I'm trying to do a search engine friendly redirect and it's not working.

<html>
<head>
<?php
                    

                    // Permanent redirection
                    

                    header("HTTP/1.1 301 Moved Permanently");
                    

                    header("Location: http://www.mysite.org/content/");
                    

                    exit();
                    

                    ?>
</head>
<body>



</body> 
</html>

error when I load the page, test.php, located in Up At Six HTTP Server Test Page (name of website is actually different):


Warning: Cannot modify header information - headers already sent by (output started at /home2/mysiteorg/public_html/test.php:7) in /home2/mysiteorg/public_html/test.php on line 13

Warning: Cannot modify header information - headers already sent by (output started at /home2/mysiteorg/public_html/test.php:7) in /home2/mysiteorg/public_html/test.php on line 16

It doesn't matter if I change the name to index.php, remove the exit(), put the php code in the body, or before the header, remove the / after content, or redirect to the index.php file located in www.mysite.org/content, it still doesn't work.

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
Headers are always to be sent before content. You placed two HMTL tags prior to sending the header to client.

You must remove any and all content including whitespace before the <?php tag which contains the header()call.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.