301Moved Permanently
This address has moved for good. Use the new one in the Location header from now on.
How you get a 301
The request is for an old address. The proxy sends 301 with the new address in Location, without asking the app. The browser follows it by itself and the second request gets a normal 200.
Who sends itProxy · App · CDN
- Browser
- CDN
- Proxy
- App
- DB
Typically the proxy or CDN, for site-wide rules such as http to https or adding www. The app sends it for individual pages that have moved.
In short
What a 301 Moved Permanently means
A 301 Moved Permanently says the thing you asked for now lives at another address, given in the Location header, and that you should use that address from now on. The browser follows it at once with a second request, so the user only notices a changed URL. Site-wide redirects, such as http to https, are typically answered by the proxy or CDN without the application being involved. Permanent is meant literally. Browsers and caches may store a 301 and skip the original address entirely next time, with no expiry unless the response sets one. That makes a mistaken 301 hard to take back: fixing the server does not reach people whose browser already remembers the old answer. For a POST, clients may also switch the method to GET; 308 exists to prevent that.
When you see a 301
1A rule sends http to https, or the bare domain to www.
How to check: Ask for the headers only and read Location.
curl -sI http://example.com/ | grep -iE '^HTTP|location'2A page was moved or renamed and the old URL points to the new one.
How to check: Follow the whole chain and count the hops. More than one is worth flattening.
curl -sIL https://example.com/old-page | grep -iE '^HTTP|location'3The server adds or removes a trailing slash.
How to check: Compare the URL you sent with Location; they differ only by the final slash.
4An old 301 is still cached in the browser after the server rule was removed.
How to check: Repeat the request with curl, or in a private window. If the redirect is gone there, the browser cached it.
Retry or not?
Nothing to retry · Follow Location
Headers that matter
- Location
- The new address. Without it the client has nowhere to go.
- Cache-Control
- Controls how long the redirect is remembered. A max-age on a new 301 keeps it reversible while you check it.
In the real world
RFC vs real deployments
RFC 9110 notes that, for historical reasons, a client may change a POST into a GET when following a 301, and browsers do. If the method and body must survive, the RFC points to 308 instead. The RFC also makes 301 cacheable by default, and browsers take that seriously: with no cache headers they can keep it indefinitely.
Seen in a real outage
A permanent redirect outlives the reason for it. The mobile carrier Three sent customers who had run out of data to an error page with a 301, and their browsers kept going there later, even on other connections.
Your turn
Which code is it?
You redirected /pricing to /plans with a 301 by mistake and removed the rule an hour later. Some users still land on /plans. Why?
Often confused with
301 questions
- Who sends a 301 redirect?
- Typically the proxy, load balancer or CDN for site-wide rules such as http to https, and the application for individual pages that moved.
- Is a 301 redirect cached?
- Yes. It is cacheable by default, and browsers can keep it indefinitely unless the response sets a cache lifetime.
- Does a 301 keep the request method?
- Not reliably. Clients may turn a POST into a GET when they follow a 301. Use 308 when the method and body must be kept.
Sources: RFC 9110: 301 Moved Permanently (section 15.4.2) ↗ · RFC 9110: Location (section 10.2.2) ↗ · Report a problem
Diagrams are our own simulations. All wording is original and paraphrases the linked sources.
Practise this in the DNS / HTTP track
Two-minute animated lessons, then boss fights from real outages. Free, no account needed.