X
Popular Searches

How to Set Up Redirects with Just HTML

Computer code.

If you want to set up a redirect to a different website, you don’t need to set up any routing rules on a web server or mess about with JavaScript; HTML has redirect tools built in using meta tags. We’ll discuss how and when to use them.

You Don’t Need JavaScript, or Fancy Routing Rules

Of course, if you have the ability to set up something better, you should take it. If you have full access to the web server your site is running on, you should probably set up a 301 or 302 redirect, or if the resource is on the same server, set up a URL rewrite so that the user isn’t affected at all. Even shared hosting with Apache can handle 301 redirects with .htaccess configuration files.

However, the real world isn’t always as pretty, and sometimes you just need to deploy an HTML page that redirects every user somewhere else. Usually, this is most useful in cases where you cannot use a proper .htaccess file, such as with certain content management systems that overwrite it.

This is still not a great solution—it’s not great for SEO, as it’s a client-side redirect, and this kind of redirect will show a white screen on the user end while waiting for the redirect to kick in. If you still want to set one up though, HTML has some tools built into it.

Using HTML meta refresh redirects, you can send a user to a new page. Create an HTML file with nothing but the following, replacing example.com with your URL:

<meta http-equiv="refresh" content="0; URL=https://www.example.com/" />

The zero before it means that this redirect will happen instantly, which is probably ideal. However, if you want to instead display the annoying “click here if you’re not redirected in five seconds message,” you can do that as well, adding a second link that users :

<head>
    <meta http-equiv="refresh" content="5; URL=https://www.example.com/" />
</head>
<body>
    <p>If you are not redirected in five seconds, <a href="https://www.example.com/">click here</a>.</p>
</body>

However, HTTP meta refresh redirects are supported in every single browser, so it’s almost always better to just redirect users instantly.

Anthony Heddings Anthony Heddings
Anthony Heddings is the resident cloud engineer for LifeSavvy Media, a technical writer, programmer, and an expert at Amazon's AWS platform. He's written hundreds of articles for How-To Geek and CloudSavvy IT that have been read millions of times. Read Full Bio »

The above article may contain affiliate links, which help support CloudSavvy IT.