Redirect Page to Another URL in PHP
- 1 minute read
The below PHP code uses the built-in
header function to redirect the user to https://example.com
:
header('Location: https://example.com');
This more complete and thorough snippet replaces the previous status code and sets it to 301, before exiting:
header('Location: https://example.com', true, 301);
exit();
There are actually a number of other ways you could go about doing this, but this is my favorite, because I find it to be the most concise and easiest to remember.
Conclusion
That’s all! Happy redirecting!