How to redirect the visitor to another page or website?

by Yang Yang on September 3, 2009

This is one of the most common tasks in website development and also one of the most frequently asked question according to some of the keyword research tools. Well, you have 3 ways to achieve a web page redirection.

  1. Use PHP header() function to modify and send a HTTP Location header:

    header("Location: /thankyou.html"); // redirect the visitor to the /thankyou.html page on the same website

    header("Location: http://www.microsoft.com"); // redirect the visitor to Microsoft

    You will need to make sure there’s no output at all before the calling of the header function to avoid any headers already sent errors.

  2. Use the meta tag of HTML:

    <meta http-equiv="refresh" content="3;url=http://www.example.com/hi.html">

    Which will simply refresh the visitor’s browser window and redirect to http://www.example.com/hi.html in 3 seconds.

  3. Use JavaScript to manipulate the browser window location object:

    <body onload="document.location='http://www.example.com/'">

Comments on this entry are closed.

{ 1 trackback }

Previous post:

Next post: