pingrobot

HTTP status codes / 301

301 Moved Permanently — HTTP Status Code

· 4 min read

Short answer

301 Moved Permanently means the resource now lives at a different URL for good, given in the Location header, and clients should use the new address from now on. It is the classic redirect for moving from HTTP to HTTPS, consolidating www and non-www, and changing URL structures. Browsers may switch a POST to a GET when following it; use 308 when the method must be kept.

301 Moved Permanently tells a client that the URL it asked for has a new, permanent home, and that it should use the new address from now on. The new address is in the Location header, and browsers follow it automatically, so visitors usually never notice the hop.

What 301 means

RFC 9110 (Section 15.4.2) says a 301 means the target resource has been assigned a new permanent URI, and future references should use one of the URIs the server provides. The server should send that URI in Location, and the client may follow it automatically.

Three details matter in practice:

  • Method change is allowed. For historical reasons, a client may turn a POST into a GET when it follows a 301. Browsers do this, so a form posted to a URL that now answers 301 loses its body on the way. RFC 9110 points to 308 Permanent Redirect when that is not acceptable.
  • It is cacheable. A 301 is heuristically cacheable, so browsers and proxies may store it and skip the original URL next time without asking the server. Browsers are known to remember 301s for a long time.
  • Link updating is only a suggestion. The RFC notes that clients that edit links could update them permanently, but most clients just follow the redirect each time.

When you see it

Server configuration and CMSs generate most 301s:

  • HTTP to HTTPS. http://example.com/ answers 301 to https://example.com/.
  • Host consolidation. www.example.com redirects to example.com, or the other way around.
  • Trailing slashes and case. /About to /about, or /blog to /blog/.
  • Site migrations. A new domain, a new URL scheme, merged or renamed pages.
  • CDNs and hosting platforms that apply "Always use HTTPS" rules at the edge.

In nginx, a typical HTTPS redirect looks like this:

server {
    listen 80;
    server_name example.com www.example.com;
    return 301 https://example.com$request_uri;
}

Pitfalls

  1. Chains. http://www.example.com to https://www.example.com to https://example.com is two hops where one would do. Each hop adds latency. Redirect straight to the final URL.
  2. Loops. A CDN that forces HTTPS combined with an origin that forces HTTP, or two rules that undo each other, sends clients in circles until they give up with a "too many redirects" error.
  3. Sticky mistakes. Because browsers cache 301s, a wrong permanent redirect can keep affecting returning visitors after you fix the server. Use a 302 or 307 while testing, then switch to 301.
  4. Losing form data. An API endpoint that moved and now answers 301 to POST requests may receive the follow-up as a body-less GET. Use 308 for moved API endpoints.
  5. Redirecting everything to the home page. When migrating, map each old URL to its real equivalent. Google's documentation says it may treat a redirect to an irrelevant page as a soft 404.

SEO notes

Google's Search Central documentation lists 301 and 308 as permanent redirects and says they are a strong signal that the redirect target should be canonical. In practice that means a properly mapped 301 is the right tool when a page moves for good. Keep internal links and sitemaps pointing at the final URL, so you do not rely on redirects for your own navigation.

How to check it

curl -I shows the redirect without following it:

curl -I http://example.com/
HTTP/1.1 301 Moved Permanently
Location: https://example.com/

To see the whole chain and where it ends, follow redirects and print each hop:

curl -sIL http://www.example.com/ | grep -iE "^(HTTP|location)"

More than one or two lines of Location means a chain worth shortening.

What it means for uptime monitoring

PingRobot's checker sends a GET and follows redirects, then judges the final response: 200 to 399 is up, anything else is down. So a working 301 from HTTP to HTTPS is invisible to the verdict; the monitor reports whatever the destination returns.

That has two consequences:

  • A broken redirect shows up as its result. A 301 that points to a missing page reports 404. A redirect loop never reaches a final response, so the check fails with an error rather than a status code.
  • Monitor the URL your visitors end on. If you monitor http://example.com and the redirect is fine but the HTTPS site is down, the alert will name the final failure, which can still be confusing. Monitoring the final HTTPS URL directly gives the clearest signal. If the redirect itself matters, for example for old links, add a second monitor for the old URL.

Start monitoring free — 10 monitors, no credit card.

Frequently asked questions

What is the difference between 301 and 308?

Both are permanent. With 301, clients may change a POST into a GET when following the redirect, for historical reasons. With 308, the method and body must stay the same. For ordinary page links that are always GET, they behave the same.

Do browsers cache 301 redirects?

They can. RFC 9110 makes 301 heuristically cacheable, and browsers often remember a 301 for a long time even without Cache-Control. Test new 301s carefully, or send an explicit Cache-Control header, because a wrong one can stick in visitors' browsers.

Does a 301 redirect hurt SEO?

A correct 301 is the standard way to tell search engines a page has moved. Google documents 301 as a permanent redirect and a strong signal that the new URL should be shown in results. Long redirect chains and redirects to irrelevant pages are what cause problems.

How long should I keep a 301 in place?

As long as old links might still be used. Bookmarks, backlinks and printed URLs can live for years, so many sites keep important 301s indefinitely.