301 Redirect in HTML: Meta Refresh Code and Server Rules

October 21, 2026
10 mins read
301 Redirect in HTML: Meta Refresh Code and Server Rules

Short answer

HTML cannot send a real 301. A 301 is an HTTP status code, so it has to come from your server, host or CDN. Inside an HTML page, the closest thing is an instant meta refresh in the head: <meta http-equiv="refresh" content="0; url=https://example.com/new-page">. Google reads an instant (0-second) meta refresh as a permanent redirect. When you can, use a true 301 instead: Redirect 301 in .htaccess on Apache, return 301 on Nginx, a header() call in PHP, or a _redirects rule on Netlify.

People searching for a "301 redirect in HTML" usually have an old .html page and want visitors and Google to land on a new URL. This guide gives you the copy-and-paste HTML redirect code first, then the server rules that send a real 301 Moved Permanently, and how to check which one your page actually returns.

An HTML meta refresh is not an HTTP 301. It makes the browser load the old page before moving on, which can slow visitors down. Google treats an instant (0-second) meta refresh as a permanent redirect. A server-side rule is still the better choice: it is faster, it works for every client, and it is easier to test. For a site move, use server-side rules and test every important old URL.

HTML Redirect Code (Copy and Paste)#

Replace the old page's content with this file, or add the meta tag to its head. The visible link is a fallback for anyone whose browser does not follow the refresh.

html<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="refresh" content="0; url=https://example.com/new-page">
  <title>This page has moved</title>
</head>
<body>
  <p>This page has moved to <a href="https://example.com/new-page">example.com/new-page</a>.</p>
</body>
</html>

The content value has two parts: the number of seconds to wait (0 means at once) and the destination URL. MDN's guide to HTTP redirections[1] recommends always setting the delay to 0 for accessibility, and Google treats any delay above 0 as a temporary redirect, so keep it at 0 when the move is permanent.

How to Add an HTML Redirect to an Old Page#

  1. Open the old HTML file (for example old-page.html) in your editor or your host's file manager.
  2. Paste the meta refresh tag inside the head, above any other content.
  3. Set the delay to 0 and the url to the full address of the new page.
  4. Add a plain link to the new page in the body as a fallback.
  5. Save the file and upload it to the same path on your server.
  6. Open the old URL in a private window and confirm it lands on the new page.

Is your redirect working? Enter your domain. You'll see the status code (301 or 302), where it lands, whether HTTPS is valid, and how fast it answers from Washington, Frankfurt and Tokyo, ranked against every redirect tested in the last 7 days.

Test my redirect

A meta refresh shows up as 200 OK in that test, because the redirect happens in the browser. If you need the status line to read 301, use one of the server rules further down.

Why Server-Side Rules Beat HTML Redirects#

When managing website migrations or URL updates, many developers look for a way to configure a 301 redirect inside an HTML document. HTTP status codes work at the protocol layer, above the markup: a 301 comes from the server, not from the page. If you are new to the status code itself, start with what a 301 redirect is.

With a server-side redirect, the server replies to the request with 301 Moved Permanently and a Location header that names the new URL. The browser does not render the old page. It requests the new URL straight away. The status code and the Location header are defined in RFC 9110[2].

An HTML redirect works differently. The server first returns 200 OK with the old page. The browser has to download and parse that HTML before the meta tag triggers navigation. That adds a step for every visitor, and the redirect only works for clients that read the markup.

Diagram comparing a server-side 301 redirect with a client-side HTML meta refresh: the 301 answers with a Location header before any page is downloaded, while the meta refresh returns 200 OK and redirects after the HTML is parsed

Instant vs Delayed Meta Refresh#

With a zero-second delay, the browser navigates as soon as it parses the tag. Google reads an instant meta refresh as a permanent redirect and a delayed one, with any value above 0 seconds, as a temporary redirect (see Google's redirect documentation[3]). The old page still has to be fetched and parsed first. For the full list of redirect methods RedirHub supports, see redirect methods explained.

MDN also notes the order browsers apply them in: an HTTP redirect always runs first, then a JavaScript redirect, and the meta refresh only after the page has fully loaded. If a page carries both a server redirect and a meta tag, keep them pointing to the same URL, or remove the tag, so they cannot disagree and loop.

JavaScript Redirect (Last Resort)#

If you can neither change the server nor edit the page head, a script can move the browser:

html<script>
  window.location = "https://example.com/new-page";
</script>

This only works for clients that run JavaScript. Google says to use JavaScript redirects only when server-side or meta refresh redirects are not possible, because rendering can fail and the redirect may never be seen.

Server 301 vs Meta Refresh vs JavaScript#

FeatureServer-side HTTP 301HTML meta refreshJavaScript (window.location)
HTTP status code301 Moved Permanently200 OK200 OK
Where it runsServer, CDN or proxyBrowser HTML parserBrowser JavaScript engine
How Google reads itPermanent redirectPermanent if instant (0 seconds), temporary if delayedFollowed after rendering; can be missed if rendering fails
What the visitor loads firstOnly the redirect responseThe old HTML pageThe old page and its script
What the client needsAny HTTP clientAn HTML parserA JavaScript engine

301 vs 302 and What Google Does With Each#

A 301 tells search engines the move is permanent and that the new URL should be treated as the canonical one. A 302 signals a temporary move, so the original URL generally stays canonical. Google applies the same permanent-or-temporary split to meta refresh: instant is permanent, delayed is temporary. For a full comparison, read 301 vs 302 redirects.

SEO and Performance Risks of HTML Redirection#

HTML-level redirects add steps that a server redirect avoids.

When a crawler meets a meta refresh, it has to fetch the old page and parse it before it finds the destination. On a large site migration that is an extra page fetch for every old URL. A JavaScript redirect adds a rendering step on top, and Google notes that rendering can fail, so the redirect may never be seen. Google advises using JavaScript redirects only when server-side or meta refresh redirects are not possible.

Visitors feel it too. The browser has to load the old page before it moves on, and on a slow mobile connection that delay is noticeable. A server-side redirect answers with the redirect itself and no page to load. In RedirHub's own redirect speed benchmark, which times only the redirect response, RedirHub's median time to first byte was 16 ms, averaged over Washington D.C., Frankfurt and Tokyo in the week to 21 November 2026. The test is run by RedirHub and most providers in it have only a few URLs measured, so read it as a guide to relative speed.

Crawlers That Do Not Run Your Page#

Not every client that fetches your URLs is a full browser. Some crawlers and scrapers read the raw HTTP response and do not render the page. A server-side 301 works for all of them, because the redirect is in the HTTP response itself. A meta refresh only works for clients that parse HTML, and a script only for clients that run JavaScript.

Public documentation on which AI crawlers follow a meta refresh is thin, so do not rely on it for pages you want those systems to find. A server-side 301 removes the question.

How to Set Up a 301 Redirect on Common Servers#

Server configuration lets you set permanent redirects without leaving legacy HTML files in your web root. The examples below move a single page.

Apache (.htaccess)#

On Apache with mod_alias, use the Redirect directive. The status can be written as 301 or as the keyword permanent (Apache mod_alias documentation[4]). If you manage many rules, see how RedirHub compares with .htaccess redirects. The single-page form looks like this:

apacheconfRedirect 301 /old-page.html https://example.com/new-page

For pattern-based changes, such as moving a whole folder, use mod_rewrite. The R=301 flag sets the status, L stops further rules and NC makes the match case-insensitive:

apacheconfRewriteEngine On
RewriteRule ^old-folder/(.*)\.html$ /new-folder/$1 [R=301,L,NC]

Nginx#

In Nginx, the return directive inside a server or location block is the simplest way to send a permanent redirect. If you would rather not edit server config for every change, see RedirHub vs Nginx redirects. An exact-match location, written with =, limits the rule to that one URL:

nginxlocation = /old-page.html {
    return 301 https://example.com/new-page;
}

PHP (a real 301 from a .php page)#

If your host runs PHP but does not let you edit server configuration, a PHP file at the old URL can send a true 301. This is the example from Google's redirect documentation[3]. It must run before any HTML is output:

php<?php
header('HTTP/1.1 301 Moved Permanently');
header('Location: https://www.example.com/newurl');
exit();

Netlify and other static hosts#

Static hosts often do not give you access to server configuration. Netlify reads redirect rules from a _redirects file or from netlify.toml. Rules in _redirects are processed first, and the first match wins (Netlify redirects documentation[5]). If your rule files grow hard to manage, see RedirHub vs Netlify redirects. In a _redirects file, the ! after the status forces the redirect even if a file exists at the old path:

text/legacy-page.html /modern-page 301!

The same rule in netlify.toml:

toml[[redirects]]
  from = "/old-path.html"
  to = "/new-path"
  status = 301
  force = true

If a host gives you no server-side option at all, an instant meta refresh is the fallback, because Google reads it as permanent. Treat it as a last resort and move to a server or edge rule when you can.

Test Your Permanent Redirects#

After you configure a redirect, check that the server sends the right headers. From a terminal, run:

bashcurl -I https://example.com/old-page.html

The output should show HTTP/1.1 301 Moved Permanently (or HTTP/2 301) and a Location header with your new URL. Then check for the usual problems:

  • Redirect chains: send URL A straight to URL C, not through URL B.
  • Redirect loops: make sure the destination does not point back to the source.
  • Browser caching: browsers cache 301 responses, so test in a private window or with curl.

To check a whole list of migrated URLs at once, use the redirect checker. If a redirect is not behaving as expected, see why a 301 redirect is not working. To see the status code, final URL and response time for a single address, run it through the redirect speed test; a meta refresh will show as 200 OK there, a server redirect as 301.

Redirect old pages at the edge

Set up 301 redirects for your old URLs without editing server files, and check each one before you launch. Pro comes with a 14-day free trial; Core starts right away.

Set up 301 redirects

When to Move Redirects Out of HTML Files#

A meta refresh can move a browser, but it is not a substitute for an HTTP 301 response. Google does read an instant meta refresh as permanent, so it is a workable fallback when you cannot change the server. For website migrations, domain changes and individual page moves, set the redirect at the server, proxy or edge layer, then test every important URL.

RedirHub serves redirects from 130 global edge locations, so you do not keep an HTML file or a config line for every old URL. Connect the domain, then in the dashboard choose Domain Redirect, fill in Redirect from and Redirect to, pick 301 · Permanent and click Create redirect. Your DNS and email stay where they are, because only the root and www records change, and automatic HTTPS is issued and renewed for both. For dozens or thousands of old pages, a bulk CSV import maps each old URL to its own new page in one go. For a step-by-step walkthrough, see setting up URL redirects, or read how to redirect a website to another domain or URL.

HTML meta refreshServer rules you maintainRedirHub
Status code200 OK, then the browser moves301, 302, 307 or 308301, 302, 307, 308 or frame
Where it is setOne HTML file per old URLServer or host configDashboard, CSV import or API
HTTPS on old domainsNeeds hosting and a certificateNeeds a certificate you renewIssued and renewed automatically, root and www
Many old URLsOne file eachOne rule each, or regexKeep the path, or map each URL from a CSV
VisibilityNoneServer logsClicks and unique visitors, plus a 404 report of URLs still requested
CostFreeFree with your hostingFrom $49/month Core; 14-day free trial on Pro

If the old pages and the new ones live on the same site and you cannot change its DNS, Integration Mode lets the site's own platform (Cloudflare Workers, Vercel / Next.js or WordPress) serve your RedirHub redirects with no DNS change, up to 50,000 rules per domain. On every connected domain, the 404 report lists old URLs that visitors still request, so you can redirect them in one click instead of hunting for them in logs.

For one or two moved pages on a site you already host, a meta refresh or a single .htaccess line is free and enough. A service starts paying off when you retire whole domains, move many URLs at once or want to see which old links still get traffic.

Sources

  1. [1]Redirections in HTTP - MDN
  2. [2]RFC 9110: HTTP Semantics
  3. [3]Redirects and Google Search
  4. [4]mod_alias - Apache HTTP Server Version 2.4
  5. [5]Redirects and rewrites overview | Netlify Docs

Frequently asked questions

You can't send a 301 status from HTML itself, because status codes come from the server. Inside the page, add an instant meta refresh to the head (content="0; url=https://example.com/new-page"), which Google reads as a permanent redirect. For a true 301, use Redirect 301 in .htaccess, return 301 in Nginx, a PHP header() call or a _redirects rule on Netlify.

Put <meta http-equiv="refresh" content="0; url=https://example.com/new-page"> inside the head of the old page and add a plain link to the new page in the body as a fallback. A 0-second delay redirects at once.

Set the delay to 5: content="5; url=https://example.com/new-page". Google treats any delayed meta refresh as a temporary redirect, and MDN recommends a 0-second delay for accessibility, so use a delay only for a notice page, not for a permanent move.

Google treats an instant meta refresh (0 seconds) as a permanent redirect and a delayed one as temporary, so an instant refresh can signal a permanent move. It is still a second-best option: the visitor has to load the old page first, and a server-side 301 works for clients that do not parse HTML. Use a meta refresh only when you cannot set a server-side rule.

Google renders pages and can follow JavaScript location redirects, but rendering can fail, so a JavaScript redirect may never be seen. Google advises using them only when server-side or meta refresh redirects are not possible.

There is little reliable public documentation either way, and crawlers differ. A server-side 301 is the safe choice, because any client that reads HTTP responses follows it without parsing HTML or running JavaScript.

Browsers cache 301 responses, so a changed rule can seem to have no effect. Test in a private window, tick Disable cache in your browser's developer tools, or use curl -I, which does not cache. While you are still settling the final destination, a short Cache-Control max-age on the redirect response limits how long a mistake sticks.

Use a 301 when the page has moved for good and the new URL should be the one search engines show. Use a 302 when the move is temporary and the original URL should stay. The 301 vs 302 guide on this blog covers the differences in detail.

Leo Astarothman

Leo Astarothman is the Brand & Content Lead at RedirHub, where he shapes the company's visual identity, educational content, product experiences, and marketing strategies. He also specializes in system design. Simplifying complex redirect infrastructure into practical resources, product experiences, and campaigns that help businesses understand and adopt modern redirect management.