HTTP 301 Moved Permanently
Updated Free mock REST & WebSocket APIs
HTTP 301 Moved Permanently — The resource has a new permanent URL, given in the Location header.
- Class
- 3xx Redirection
- Defined in
- RFC 9110 §15.4.2
- Official
- Yes (IANA registry)
- Cacheable by default
- Yes (heuristically, per RFC 9110)
Try it: get a real 301 response
Our test endpoint answers every request with 301 Moved Permanently.
curl -i https://mockfox.dev/api/status/301Use it in tests, health-check monitors or to see how your client handles a 301. Add ?delay=2000 to slow it down.
What does HTTP 301 mean?
301 Moved Permanently tells the client that the resource now lives at the URL in the Location header, and that future requests should use that new URL. Browsers cache 301s aggressively (often indefinitely), and search engines transfer the old URL's ranking signals to the new one.
For historical reasons, clients may change a POST into a GET when following a 301 (browsers do). If the method must be preserved, use 308 Permanent Redirect.
When is 301 used?
- HTTP → HTTPS and
www→ apex (or the reverse) canonicalisation. - A page's URL changed after a site restructure or CMS migration.
- A domain move:
old-brand.com/*→new-brand.com/*. - Trailing-slash normalisation (
/about/→/about).
Why you're seeing 301
- The site owner deliberately moved the page or enforces a canonical URL.
- Redirect loops ("ERR_TOO_MANY_REDIRECTS") happen when two rules redirect to each other — e.g. a CDN in Flexible SSL mode requesting HTTP from an origin that redirects to HTTPS.
What to do about 301
If you're visiting the site
- Your browser follows a 301 automatically. If you're stuck in a redirect loop, clear the site's cookies and cached data (browsers cache 301s), or try a private window.
- Update bookmarks to the new address.
If you run the site or API (developers)
- Redirect each old URL to its closest equivalent page, not everything to the homepage (Google treats that as a soft 404).
- Avoid chains (A → B → C): point old URLs straight at the final destination.
- Test before shipping — a wrong 301 is cached by browsers and hard to undo. Use 302/307 while experimenting.
- Keep redirects in place for at least a year after a migration (ideally forever).
Sending 301: server examples
nginx
server {
listen 80;
server_name example.com www.example.com;
return 301 https://example.com$request_uri;
}
# A single moved page
location = /old-page { return 301 /new-page; }Express
app.get("/old-page", (req, res) => res.redirect(301, "/new-page"));Next.js
// next.config.ts — note: permanent: true sends 308, not 301
export default {
async redirects() {
return [{ source: "/old-page", destination: "/new-page", permanent: true }];
},
};
// To force a literal 301 in a route handler:
export function GET() {
return new Response(null, { status: 301, headers: { Location: "/new-page" } });
}Example 301 response
HTTP/1.1 301 Moved Permanently Location: https://example.com/new-page Content-Type: text/html Content-Length: 162 Cache-Control: max-age=31536000
301 vs 302 vs 307 vs 308
301 and 308 are permanent (the new URL replaces the old one, including in search results); 302 and 307 are temporary (keep using the old URL). 307 and 308 additionally forbid changing the method, so a POST stays a POST with its body. For SEO, Google treats 301 and 308 the same.
Related status codes
- 308 Permanent RedirectThe resource has a new permanent URL and the client must repeat the request with the same method and body.
- 302 FoundThe resource is temporarily at a different URL, given in the Location header.
- 307 Temporary RedirectThe resource is temporarily at another URL and the client must repeat the request with the same method and body.
Related tools
Frequently asked questions
Does a 301 redirect hurt SEO?
No. Google passes ranking signals through 301 (and 308) redirects and eventually indexes the destination URL instead of the old one. Long chains and redirects to irrelevant pages are what cause problems.
How do I undo a cached 301?
You can't force browsers to forget it remotely. Users must clear cached data for the site. On the server, redirect the new URL back (careful of loops) or serve the old URL again; next time a browser revalidates it'll pick that up. That's why you should test with 302 first.
301 or 308?
Both are permanent. 308 guarantees the HTTP method and body are kept, which matters for API endpoints receiving POST/PUT. For ordinary pages either works; 301 has the widest legacy support.