Science, Tech, Math › Computer Science How to Redirect With PHP Share Flipboard Email Print iStock / Getty Images Plus Computer Science PHP Programming Tutorials MySQL Commands Perl Python Java Programming Javascript Programming Delphi Programming C & C++ Programming Ruby Programming Visual Basic View More By Angela Bradley Angela Bradley Computer Science Expert B.A, History, Eastern Oregon University Angela Bradley is a web designer and programming expert with over 15 years of experience. An expert in iOS software design and development, she specializes in building technical hybrid platforms. Learn about our Editorial Process Updated on September 09, 2018 A PHP forwarding script is useful if you want to redirect one page to another so that your visitors can reach a different page than the one they land on. Fortunately, it's really easy to forward with PHP. With this method, you seamlessly transfer visitors from the web page that no longer exists to the new page without requiring them to click a link to continue. How to Redirect With PHP On the page that you want to redirect elsewhere, change the PHP code to read like this: The header() function sends a raw HTTP header. It must be called before any output is sent, either by normal HTML tags, by PHP, or by blank lines. Replace the URL in this sample code with the URL of the page where you want to redirect visitors. Any page is supported, so you can transfer visitors to a different webpage on your own site or to a different website entirely. Because this includes the header() function, be sure that you do not have any text sent to the browser before this code, or it will not work. Your safest bet is to remove all the content from the page except for the redirect code. When to Use a PHP Redirect Script If you remove one of your web pages, it's a good idea to set up a redirect so that anyone who bookmarked that page is transferred automatically to an active, updated page on your website. Without the PHP forward, visitors would remain on the dead, broken, or inactive page. The benefits of this PHP script are as follows: Users are redirected quickly and seamlessly.When the Back button is clicked, visitors are taken to the last viewed page, not the redirect page.The redirect works on all web browsers. Tips for Setting up a Redirect Remove all code but this redirect script. Mention on the new page that users should update their links and bookmarks. Use this code to create a drop-down menu that redirects users. Cite this Article Format mla apa chicago Your Citation Bradley, Angela. "How to Redirect With PHP." ThoughtCo, Feb. 16, 2021, thoughtco.com/how-to-redirect-with-php-2693922. Bradley, Angela. (2021, February 16). How to Redirect With PHP. Retrieved from https://www.thoughtco.com/how-to-redirect-with-php-2693922 Bradley, Angela. "How to Redirect With PHP." ThoughtCo. https://www.thoughtco.com/how-to-redirect-with-php-2693922 (accessed May 31, 2023). copy citation Featured Video