Skip to content

301 Moved Permanently

The page has moved to a new URL for good. Browsers and search engines follow the Location header and update their links.

What 301 Moved Permanently means

Send 301 when a URL changes permanently: a new domain, HTTP to HTTPS, a renamed slug. Search engines move the old URL's ranking signals to the new one, and browsers cache 301s, sometimes for a long time.

For historical reasons, clients may change a POST into a GET when following a 301. If the method and body must be kept, use 308 Permanent Redirect. For a temporary move, use 302 or 307.

Common causes

  • A redirect loop, where URL A redirects to B and B redirects back to A, often caused by competing http/https or www/non-www rules.
  • A chain of several redirects left over from more than one site migration.
  • A cached 301 that the browser keeps following after the server rule was removed.

How to fix 301 Moved Permanently

  1. Run curl -I on the URL or open the browser's network tab to see every hop and its Location header.
  2. Point old URLs straight to the final URL in one hop, and keep https and www rules in one place (only at the CDN or only in nginx, for example).
  3. If a browser is stuck on a stale 301, clear its cache or test in a private window. Use 302 while you are still testing a new redirect.

Headers that go with it

  • Location

Example response

HTTP/1.1 301 Moved Permanently
Location: https://example.com/new-page
Content-Type: text/plain; charset=utf-8

301 Moved Permanently

How to check for a 301 response

cURL

# Print only the status code (no -L, so the redirect isn't followed)
curl -s -o /dev/null -w "%{http_code}\n" https://example.com/

JavaScript (Node.js)

const res = await fetch("https://example.com/", { redirect: "manual" });
if (res.status === 301) {
  console.log(res.status, res.statusText, res.headers.get("location"));
}

Python

import requests

res = requests.get("https://example.com/", allow_redirects=False)
if res.status_code == 301:
    print(res.status_code, res.reason, res.headers.get("Location"))

Go

client := &http.Client{
	CheckRedirect: func(*http.Request, []*http.Request) error {
		return http.ErrUseLastResponse
	},
}
res, err := client.Get("https://example.com/")
if err != nil {
	log.Fatal(err)
}
defer res.Body.Close()
if res.StatusCode == 301 {
	fmt.Println(res.Status, res.Header.Get("Location"))
}

Specification

301 Moved Permanently is defined in RFC 9110, section 15.4.2.

  • 308

    Permanent Redirect

    The resource has moved permanently to a new URL, and clients must keep the same method and body when following the redirect.

  • 302

    Found

    The resource is temporarily at a different URL. Clients follow the Location header but keep using the original URL in future.

  • 307

    Temporary Redirect

    The resource is temporarily at another URL, and the client must repeat the exact same request there, keeping the method and body.

← all 63 HTTP status codes

Type to search posts, tools and projects.

Keyboard shortcuts

Search+Kor/
Go to homegthenh
Go to bloggthenb
Go to projectsgthenp
Go to timelinegthent
Show this help?
Close search or helpesc