3xx Redirection

HTTP 301 Moved Permanently

The resource has been permanently moved to a new URL. Clients should update bookmarks.

When is 301 used?

  • Domain migration (http to https)
  • Permanently changed URL structures
  • SEO permanent redirects

How to handle a 301 response

Follow the Location header. Most HTTP clients do this automatically, and curl -L follows redirects on the command line. Update links and sitemaps that point at permanently redirected URLs.

Check the status code a URL returns from the command line:

curl -s -o /dev/null -w "%{http_code}\n" https://example.com

How to return 301 from your server

Node.js (Express)

res.status(301).json({ message: 'Moved Permanently' });

Python (Flask)

return {"message": "Moved Permanently"}, 301

Go (net/http)

w.WriteHeader(301)

Frequently Asked Questions

What does HTTP 301 mean?

301 Moved Permanently: The resource has been permanently moved to a new URL. Clients should update bookmarks.

Is 301 an error?

No. 301 is in the 3xx Redirection class. Redirection: the client must take additional action, usually requesting a different URL.