xernt.com




Xernt helps you find up-to-date answers & allows to take a part in building human knowledge database.
This Post below ↓ is only visible to you.
It is sheduled to delete with all the changelog & comment data attached. You can cancel deletion at any time.
4 weeks left
TIP. Editing item cancels the deletion shedule automatically.
PHP REDIRECT 301, php header 301

PHP REDIRECT 301, php header 301Edit

 
 
To make 301 redirect in php you need to use the code below (function: header()):


header('Location: http://path-of-power.com/php-redirect-301',true,301);
exit;

?>


or (better to use, because you don't need to put {} (brackets) when it's only 1 instruction after IF, ELSE)


exit(header('Location: http://path-of-power.com/php-redirect-301',true,301));


?>




header() Send a raw HTTP header

void header ( string $string [, bool $replace = true [, int $http_response_code ]] )
header() is used to send a raw HTTP header. See the ? HTTP/1.1 specification for more information on HTTP headers.

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.


/* This will give an error. Note the output
* above, which is before the header() call */
header('Location: http://www.example.com/');
?>
Edit
Comment · pm1  · 2 years ago
<dotNetFollower> Hello!Nice post! I'd like to note that there are at least two more ways to make the redirect,
especially if headers are already sent: Meta refresh and JavaScript redirect. I described them wider
in my article here - PHP: Redirection Overview.Thank you!
<AndyPSV> http://path-of-power.com/php-engine-framework-multilingual-friendly-urls-templates-with-modules,399
<AndyPSV> fixed, thanks
<Pac-Man> header('Location: http://path-of-power.com/php-redirect-301' ,true, 301);Sorry, this way...
without the ' at the end.
<Pac-Man> header('Location: http://path-of-power.com/php-redirect-301' ,true, 301');That's the correct
way. – Andrzej Jeziorski  2 months ago · Reply
Please login or create an account to post a comment.
Follow Post
Related Posts
2,620 views


 
 
136 online
About · Blog · Explore · Privacy · Terms · Help  up

These items will be permanently deleted and cannot be recovered. Are you sure?