A blog & community for non-professional web designers, programmers, webmasters, and other web savvies.

3 Ways to Redirect Your Page

August 23, 2010 - 12:00am -- aashni

Here are some nifty little codes that will let you redirect a visitor from the page they are on to a new page. There are three versions to this code; an HTML, a PHP and a Javascript version.

HTML Redirect

<html>
<head>
<meta http-equiv="Refresh" content="0; URL=URLHERE">
</head>
<body>
</body>
</html>

The HTML version is pretty fail-proof, but is probably one of the "slower" redirectors. To use this, change the number in content="0"; to however many seconds you would like it to delay the page for. You will want to delay the page if you have a banner or something written on the page that says "Sorry the page you are looking for is not available. Redirecting back to ______". If you want it to redirect the page straight away, then simply leave it as 0.

Change the URLHERE to the one that you would like to use.

PHP Redirect

<?PHP
//Put the URL of the page you wish to redirect to below
header('Location: URLHERE');
?>

This must go at the top of the page, or before any output text, or else you will get a PHP error. It is considered a lot faster than HTML, which is why it's often used more. Simply change the URLHERE to the URL you would like to be redirected to. You may need to find out from your host if PHP is allowed. The PHP method is the most preferred and fastest as the server starts processing the request before anything else can be sent to the browser.

JavaScript Redirect

<script type="text/javascript"><!--
window.location = "URLHERE";
//-->
</script>

This will only work if the user has javascript enabled in their browser. Change URLHERE to the URL you want the page to be redirected to.

Forum Board: 

@IceCaves on Twitter

    Stay Connected

    Twitter Facebook Tumblr Google+ Glaciallis Google RSS

    *Follow us on Twitter or Facebook to also follow minor site updates that don't make it to the homepage news.