You can use a simple PHP script to redirect a user from the page they entered to a different web page. One reason you may want to do this is that the page they are trying to access no longer exists. Using this method, they can be seamlessly transfered to the new page without having to click a link to continue.

  • Users are redirected quickly and seamlessly
  • When using the ‘Back’ button, the user is taken to the last viewed page, not the redirect page
  • Works on all browsers

Here’s How:

    1. <?php
    2. header('Location:');
    3. die();
    4. $f = fopen('demo.txt','w+');
    5. fwrite($f,'Test');
    6. fclose($f);
    7. ?>

    Change the code on the redirect page to be simply this. You need to replace the URL above with the URL you wish to direct to.

  1. Be sure that you do not have any text sent to the browser before this, or it will not work. Your safest bet is to simply remove all content from the page but the redirect code.

    //this will NOT work, the browser received the HTML tag before the script
    header( ‘Location:’ ) ;


  1. Remove all code but this
  2. Mention on the new page that user’s should update their links and bookmarks

Also Read:

Karthik is a mechanical engineer by profession and is also a web freak who loves to blog about interesting things happening on the web