Skip to main content
All articles
  • HTML
  • Redirects
  • SEO
  • Static Hosting
  • GitHub Pages
  • Netlify

HTML Redirect: Meta Refresh Code, JavaScript and Real 301s

Published 11 min read

On this page 8 sections

To make an HTML redirect, put a meta refresh tag in the <head> of the old page, and the browser loads the new address the moment the page arrives:

html
<meta http-equiv="refresh" content="0; url=https://example.com/new-page/">

That one line is a meta refresh redirect. The server still answers the old address with a 200 and a small HTML page, and the browser does the moving; Google treats an instant one as a permanent redirect, so it's a fair stand-in. Where your host lets you write a server-side 301, though, the 301 is the better tool, and most static hosts now let you write one.

The tag predates every static host on this page and still works on all of them, because the browser does the work and the host only has to serve a file. Below: a stub page to copy, the JavaScript version, what curl gets back from each kind of redirect, and which hosts can send a real 301.

The HTML redirect code: a meta refresh page you can copy

The one-liner works, but a redirect page in HTML that does the job properly is only a few lines longer. Save this as the old file (say old-page.html, or old-page/index.html if the old address ended in a slash):

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

Line by line:

  • <meta charset="utf-8"> comes first, as it should on any page.
  • The meta refresh goes straight after it. The HTML standard only allows a refresh <meta> inside <head> (or a <noscript> inside <head>), so "head or top of the file?" has one answer.
  • content="0; url=..." is the delay in seconds, a semicolon, then url= and the address, all inside the same pair of quotes. 0 means instant, and 0 is the only number worth using (more on that below).
  • <link rel="canonical"> tells search engines which address you'd like them to keep.
  • The visible link catches anyone whose browser has refresh turned off, and it gives a crawler a plain link to follow.

The address can be a full URL, which is how you redirect to another website, or a root-relative path like /new-page/ when you redirect to another page on the same site.

The part that matters on a static site is the file name: the stub has to live exactly where the old page lived, so the old address still resolves. If the old page was /about-us.html, the stub is about-us.html; if it was /about-us/, the stub is about-us/index.html. Getting that file online is the same job as putting any HTML file online.

JavaScript redirect: when a script is the better tool

A JavaScript redirect is one line too, and there are two versions worth knowing:

html
<script>
  // Replaces the old page in the history: Back skips it
  window.location.replace("https://example.com/new-page/");
</script>
html
<script>
  // Adds a history entry: Back returns to the old page, which redirects again
  window.location.href = "https://example.com/new-page/";
</script>

With href, the old page stays in the history, so Back lands on the stub, which promptly sends the visitor forward again; that's the "my Back button is broken" complaint on every forum thread about redirects. replace() swaps the stub out, which is what you want for a moved page.

Where a script earns its place is a redirect that depends on something the meta tag can't see. On a stub page, keeping the #section part of the old address is the classic case: the fragment never reaches the server, and a meta refresh has no way to read it. (A real 301 keeps the fragment with no script at all: RFC 9110 has the browser carry the original #section over when the Location header has none of its own.)

html
<script>
  window.location.replace("https://example.com/new-page/" + location.search + location.hash);
</script>

The same goes for redirecting only on a condition, such as a query value or a date.

Two things to know before leaning on a script. MDN's Redirections in HTTP gives the order of precedence: HTTP redirects run first, then JavaScript, then the meta refresh, because the <meta> redirect waits until the page has finished loading. So a stub can carry both, with the script for browsers and the meta tag as the fallback when scripting is off. And Google is blunt about it in Redirects and Google Search: "Only use JavaScript redirects if you can't do server-side or meta refresh redirects." Google runs JavaScript in a later rendering step, and if rendering fails, it says, it "might never see" the redirect.

What a browser and Google actually get back (curl test, November 12, 2026)

An HTML redirect and a 301 look the same to someone clicking a link, but the server's answers differ. We ran curl -sI against public examples of a meta refresh stub and of server 301s on November 12, 2026, plus a Hostsmith test site on its own domain, and kept only the status line, location and, for the Hostsmith row, cache-control:

MethodExample checkedStatus linelocationWhat's in the bodyHow Google treats it
Meta refresh + JS stub (jekyll-redirect-from on GitHub Pages)https://jekyllrb.com/docs/home/HTTP/2 200noneA stub page: canonical link, location= script, meta refresh with 0, noindex, a "Click here" linkInstant meta refresh: permanent
Server 301 on a Netlify-hosted docs sitehttps://docs.netlify.com/routing/redirects/HTTP/2 301/manage/routing/redirects/overviewNothing the browser needs301: permanent
Server 301 on a Cloudflare-hosted docs sitehttps://developers.cloudflare.com/pages/platform/redirects/HTTP/2 301/pages/configuration/redirects/Nothing the browser needs301: permanent
Server 301 on a Hostsmith test site on its own domainhttps://redirects.hostsmith.click/oldHTTP/2 301/new (and /new?utm_source=x for /old?utm_source=x)Nothing the browser needs; cache-control: no-store301: permanent

The Netlify and Cloudflare rows are pages served by those companies' own hosting; the responses show a 301, though not which config file produced it. A JavaScript-only redirect has no row because there's nothing to show: the page answers 200, and anything that doesn't run scripts never sees a redirect.

Here's the first row in full, because it shows what "HTML redirect" means at the wire level:

text
$ curl -sI https://jekyllrb.com/docs/home/
HTTP/2 200
html
<!DOCTYPE html>
<html lang="en-US">
  <meta charset="utf-8">
  <title>Redirecting&hellip;</title>
  <link rel="canonical" href="https://jekyllrb.com/docs/">
  <script>location="https://jekyllrb.com/docs/"</script>
  <meta http-equiv="refresh" content="0; url=https://jekyllrb.com/docs/">
  <meta name="robots" content="noindex">
  <h1>Redirecting&hellip;</h1>
  <a href="https://jekyllrb.com/docs/">Click here if you are not redirected.</a>
</html>

That's the page jekyll-redirect-from writes, and it's a tidy stub: the script fires first, the meta refresh catches browsers without JavaScript, the link catches everyone else, and noindex keeps the stub itself out of search results. The redirect works the same without that line, so adding it to the stub from the first section is optional. Compare the Hostsmith row:

text
$ curl -sI https://redirects.hostsmith.click/old
HTTP/2 301
cache-control: no-store
location: /new

The server answers before any HTML exists. A 301 is understood by everything that speaks HTTP, curl, link checkers and feed readers included, while a meta refresh only works for software that downloads the page, parses it and decides to follow the tag. The cache-control: no-store line tells browsers and caches not to store that response; the status-code section below says why that matters.

Does a meta refresh redirect hurt SEO?

Not much, if it's instant. Google's Redirects and Google Search page, checked November 12, 2026, splits the HTML meta redirect in two:

  • An instant one "triggers as soon as the page is loaded in a browser. Google Search interprets instant meta refresh redirects as permanent redirects."
  • A delayed one "triggers only after an arbitrary number of seconds set by the site owner. Google Search interprets delayed meta refresh redirects as temporary redirects."

That second line is the catch. Google files 301 and 308 as permanent and 302, 303 and 307 as temporary, and for temporary ones, it says, "the indexing pipeline doesn't use the redirect as a signal that the redirect target should be canonical." So the old "You will be redirected in 5 seconds" page asks Google to keep showing the old address.

Accessibility points the same way. The W3C's WCAG failure F40 is "using meta redirect with a time limit", and it fails success criteria 2.2.1, 2.2.4 and 3.2.5, because a page that jumps after a delay can pull someone away mid-sentence. F40 says a zero-second redirect is acceptable, "since the redirect is instant", though it adds that server-side methods are preferable. MDN puts it shorter: "Always set it to 0."

So an instant meta refresh is a workable redirect on a host with no redirect rules, a delayed one costs you on both counts, and where a 301 is available, use the 301.

301 vs 302 vs 307 vs 308: which status code to send

A 301 redirect says the page moved for good, a 302 redirect says it's coming back, and 308 and 307 are the strict versions of those two that keep the request method. The definitions come from RFC 9110, the method behavior from MDN, and Google's treatment from its redirects page (all checked November 12, 2026):

CodeNamePermanent?Does the request method survive?Google treats it asUse it for
301Moved PermanentlyYesGET stays GET; a POST may become GETPermanentA page that moved for good
302FoundNoSame as 301TemporaryA short-lived move: maintenance, a seasonal page, a test
303See OtherNoAlways becomes GET (the body is dropped)TemporarySending a browser on after a form submission
307Temporary RedirectNoMethod and body keptTemporaryA temporary move where the method matters
308Permanent RedirectYesMethod and body keptPermanentA permanent move where the method matters

The pairs are history: RFC 9110 notes that early browsers split on whether to resend a POST after a 301 or 302, practice settled on GET, and 307 and 308 were added later as the strict versions. A static site serves GET requests, so 301 and 308 behave the same for a moved page. The rule that covers most cases: moved for good, 301; back soon, 302.

One more property of the permanent pair: RFC 9110 calls 301 and 308 "heuristically cacheable", so unless the response's cache headers say otherwise, a browser may keep the redirect and reuse it without asking the server again (302 and 307 get no such line). A wrong 301 can go on misdirecting visitors after you've fixed the rule, unless it was sent with a header like the no-store on the Hostsmith response above. Put the rule live, check it with curl -sI, then announce the move.

On a static host you write the status code at the end of the _redirects line, and it's worth writing it every time, because the defaults differ. Netlify and Hostsmith default to 301 when the code is left off; Cloudflare Pages defaults to 302. The same file, copied across, quietly turns a permanent move into a temporary one.

Which static hosts let you set a real 301 (GitHub Pages doesn't)

Netlify, Cloudflare Pages, Vercel and Hostsmith all read redirect rules you write; GitHub Pages gives you nowhere to write one. A static host runs no server code of yours, which is what makes a site static, so it all comes down to a rules file. Checked against each host's docs on November 12, 2026:

HostHow you write a redirectCode when you leave it offWhen a file exists at the old pathWorth knowing
GitHub PagesNo redirect rules. jekyll-redirect-from writes meta refresh pages; other sites need hand-written stubsNone (stubs answer 200)Not applicableThe plugin is on GitHub Pages' supported list (version 0.16.0)
Netlify_redirects file or netlify.toml301The file wins unless you add ! to the codeQuery strings pass on for 200, 301 and 302; paths match with or without a trailing slash
Cloudflare Pages_redirects file in the build output302The redirect wins2,000 static and 100 dynamic rules; not applied to Pages Functions routes
Vercelredirects in vercel.json308 (permanent defaults to true; false sends 307)Not checkedstatusCode sets 301, 302 or 303 instead
Hostsmith_redirects file, or rules in the dashboard, API, SDK or MCP301The redirect winsOn your own domain only (Pro plan and up); 20,000 rules per source

Sources: Netlify redirect options, Cloudflare Pages redirects, Vercel's vercel.json reference, the jekyll-redirect-from README and GitHub Pages' versions.json, and Hostsmith's redirects docs, all checked November 12, 2026.

The _redirects format is the same on the three hosts that read it: old path, new path, code, one rule per line, with * as a splat:

text
/old-page    /new-page    301
/blog/*      /posts/:splat    301

On Netlify, a leftover old-page.html in the build beats your rule until you write 301!; on Cloudflare Pages and Hostsmith the rule answers first.

GitHub Pages is the odd one out. It does send 301s of its own, for example from /about to /about/ when the page is a folder (the trailing-slash table in our Astro guide has the details), but there's no file or setting where you can write one. On a Jekyll site, add the plugin to _config.yml and list the old addresses in each page's front matter:

yaml
# _config.yml
plugins:
  - jekyll-redirect-from
yaml
# at the top of the page that moved
redirect_from:
  - /old-page/
  - /2019/03/old-post-title/

The plugin's own README is plain about what that does: it serves an HTML file with a refresh tag, and "No .htaccess file, nginx conf, xml file, or anything else will be generated." It can't send a 301. If you need real redirects, that's one of the reasons people move off GitHub Pages.

Moving a whole site

When a whole site moves, export the old URL list first (the sitemap is the easiest source), write one rule per changed path, and check every old URL before the switch. Webflow hands you a CSV of 301s, covered in keeping URLs working after leaving Webflow; for a WordPress site exported to static files, compare the export's addresses with the old sitemap before switching; and an archived Weebly site can end up with old .html addresses that no longer match the file names, each of which needs a rule or a stub.

That last check is the step that gets skipped, and it's three lines of shell. Put the old addresses in a text file, one per line:

sh
while read -r url; do
  curl -s -o /dev/null -w '%{http_code} %{url_effective} -> %{redirect_url}\n' "$url"
done < old-urls.txt

Here's what it printed on November 12, 2026, for three of the curl-table addresses plus /old/ with a trailing slash:

text
200 https://jekyllrb.com/docs/home/ -> 
301 https://developers.cloudflare.com/pages/platform/redirects/ -> https://developers.cloudflare.com/pages/configuration/redirects/
301 https://redirects.hostsmith.click/old -> https://redirects.hostsmith.click/new
301 https://redirects.hostsmith.click/old/ -> https://redirects.hostsmith.click/new

You want a 301 (or 308) with the right address after the arrow. A 200 with nothing after it is either a meta refresh stub (open it and check where the tag points) or a page that never got a rule; a 404 leads nowhere. A 000 means curl never got an answer, often because the file has Windows line endings.

Redirects on Hostsmith

Hostsmith is our static host, and the _redirects file from the previous section works on it unchanged. Deploy it with the site, or add server redirects in the site's Redirects panel, through the API, the SDK or MCP. Panel rules survive later deploys and override a file rule for the same path; the panel also tests a path to show which rule answers, and it imports a CSV or Webflow's 301 export as is. The visitor's query string carries over, as the utm_source row in the curl table shows.

The plain limits: server redirects work on your own domain, so on the Pro plan and up. A site on a hostsmith.link address, which is what Free and Starter sites get, has no redirect rules on any plan, and there the HTML redirect stub from the first section does the job. The caps are the same on every plan that has redirects: 1 MB and 20,000 rules per source, 1,000 of them with a * or a placeholder. There are no 200 rewrites (so no single-page-app fallback), no 404 rules, no country or language conditions, and the old path can't be a full URL.

Frequently Asked Questions