Hi;
I don’t know PHP and so I’d like feedback on the best PHP code to use for a 301 redirect (that Google recognizes)
<?php
header(‘HTTP/1.1 301 Moved Permanently’);
header(‘Location: http://www.site.com/newpage’);
?>
<?php
header(“HTTP/1.1 301 Moved Permanently”);
header("Location: [newdomain.com…]
exit();
?>
<?php
header( ‘Location: http://www.yoursite.com/new_page.html’ ) ;
?>
I found all of these online and am not sure if one is “better” than the others (in terms of retaining link equity)
Thanks
The first two examples are the same, the second has a syntax error, but the concept is the same.
Now what differs from the first 2 examples and the last? The last one doesn’t tell search engines that the page is permanently moved and they need to update their index.
So if you want to indicate a permanent move, use the first example (the second example is moot, since it is the same but with syntax errors).
The 2nd one also has this:
exit();
Should I include that part?
You can. It just ensures if you have any code following that line, it won’t be executed.