Web Development Course:
TL;DR – PHP redirect refers to the process of transferring users from one page to another without their interaction with hyperlinks. To make PHP redirect to another page, you need to use the predefined header function.
The true nature of redirects and their use
PHP redirects and redirection in general are for transferring users from one website to another. Many website owners use them during the reconstruction of their domains, or after merging several pages. Of course, redirection is necessary for some of the essential features, like integrating payment gateways.
How to create a PHP redirect?
header redirect is a simple way of initiating a server-side redirect. In the following example, you can see the code for making PHP redirect to a page:
<?php header('Location: https://www.bitdegree.org'); exit; ?>
However, PHP redirect is of the 302 type, meaning that it is more suitable for temporarily redirection (like site maintenance). You can fix this issue by making the redirect 301, which is for setting redirects permanently. Simply add
301 to the previous code example:
header('Location: https://www.bitdegree.org', true, 301);
Note: 301 redirects are the most SEO-friendly. Search engines understand that the content has been moved permanently, and that not only the location has changed.
How to Select the Type of a URL Redirect
Get to know 301, 302 and other types of URL redirects! Find explanations for all URL redirects & learn to create them in various languages and frameworks.