When you need to move a page from one location to another, it’s important to redirect users from the old location to the new location. This is where a 301 redirect comes in handy. A 301 redirect is a permanent redirect, which tells search engines that the old page has been moved to a new location permanently and the search engines should update their index to reflect this change.
In this article, we’ll show you how to implement a permanent redirect (301) in PHP.
- Edit the PHP file: The first step to implement a 301 redirect in PHP is to edit the PHP file. Open the PHP file that you want to redirect in a text editor, such as Notepad or Sublime Text.
- Add the header function: Add the following code to the top of the PHP file:
Make sure to replace “http://www.example.com/new-page.php” with the new location of your page.
- Save the PHP file: Once you have added the code, save the PHP file and upload it to the server.
- Test the redirect: After uploading the PHP file, test the redirect by visiting the old location of your page in your web browser. If the redirect is working, you should be automatically redirected to the new location of your page.
In this article, we have shown you how to implement a permanent redirect (301) in PHP. By using a 301 redirect, you can ensure that your users are always directed to the correct location of your page, and that search engines are updated with the correct location.