Redirect from an HTML page


Is it possible to set up a basic HTML page to redirect to another page on load?

12/8/2019 7:37:33 AM

Accepted Answer

Try using:

<meta http-equiv="refresh" content="0; url=" />

Note: Place it in the head section.

Additionally for older browsers if you add a quick link in case it doesn't refresh correctly:

<p><a href="">Redirect</a></p>

Will appear as


This will still allow you to get to where you're going with an additional click.

7/21/2017 9:31:35 AM


<script type="text/javascript">
    window.location.href = "";

Meta tag

<meta http-equiv="refresh" content="0;url=">

I would also add a canonical link to help your SEO people:

<link rel="canonical" href=""/>

The following meta tag, placed between inside the head, will tell the browser to redirect:

<meta http-equiv="Refresh" content="seconds; url=URL"> 

Replace seconds with the number of seconds to wait before it redirects, and replace URL with the URL you want it to redirect to.

Alternatively, you can redirect with JavaScript. Place this inside of a script tag anywhere on the page:

window.location = "URL"

This is a sum up of every previous answers plus an additional solution using HTTP Refresh Header via .htaccess

1. HTTP Refresh Header

First of all, you can use .htaccess to set a refresh header like this

Header set Refresh "3"

This is the "static" equivalent of using the header() function in PHP

header("refresh: 3;");

Note that this solution is not supported by every browser.

2. JavaScript

With an alternate URL:

    setTimeout(function(){location.href=""} , 3000);

Without an alternate URL:


Via jQuery:


3. Meta Refresh

You can use meta refresh when dependencies on JavaScript and redirect headers are unwanted

With an alternate URL:

<meta http-equiv="Refresh" content="3; url=">

Without an alternate URL:

<meta http-equiv="Refresh" content="3">

Using <noscript>:

    <meta http-equiv="refresh" content="3" />


As recommended by Billy Moon, you can provide a refresh link in case something goes wrong:

If you are not redirected automatically: <a href=''>Click here</a>



If you are looking forward to follow modern web standards, you should avoid plain HTML meta redirects. If you can not create server-side code, you should choose JavaScript redirect instead.

To support JavaScript-disabled browsers add a HTML meta redirect line to a noscript element. The noscript nested meta redirect combined with the canonical tag will help your search engine rankings as well.

If you would like to avoid redirect loops, you should use the location.replace() JavaScript function.

A proper client-side URL redirect code looks like this (with an Internet Explorer 8 and lower fix and without delay):

<!-- Pleace this snippet right after opening the head tag to make it work properly -->

<!-- This code is licensed under GNU GPL v3 -->
<!-- You are allowed to freely copy, distribute and use this code, but removing author credit is strictly prohibited -->
<!-- Generated by -->

<link rel="canonical" href=""/>
    <meta http-equiv="refresh" content="0; URL=">
<!--[if lt IE 9]><script type="text/javascript">var IE_fix=true;</script><![endif]-->
<script type="text/javascript">
    var url = "";
    if(typeof IE_fix != "undefined") // IE8 and lower fix to pass the http referer
        document.write("redirecting..."); // Don't remove this line or appendChild() will fail because it is called before document.onload to make the redirect as fast as possible. Nobody will see this text, it is only a tech fix.
        var referLink = document.createElement("a");
        referLink.href = url;
    else { window.location.replace(url); } // All other browsers
<!-- Credit goes to -->

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]