301 Moved Permanently
Fault: Neither
TL;DR
All future requests should use the new URL provided in the Location header.
The resource has been permanently moved to a new URL.
What HTTP 301 Moved Permanently Means
The resource has been permanently moved to a new URL.
All future requests should use the new URL provided in the Location header.
Common Causes
- Website migration
- URL structure change
- Permanent content relocation
How to Fix It (For Visitors)
- Update bookmarks to new URL
- Browser should automatically redirect
How to Fix It (For Developers/Admins)
- Update internal links to new URL
- Use for permanent URL changes
- Set Location header
Returning a 301 Moved Permanently (Code Examples)
If you build APIs or web apps, here is how to send an HTTP 301 response and how to test for it:
Node.js (Express)
app.get('/resource', (req, res) => {
res.status(301).json({ error: 'Moved Permanently' });
});
Python (Flask)
@app.route('/resource')
def resource():
return jsonify(error='Moved Permanently'), 301
PHP
<?php
http_response_code(301);
header('Content-Type: application/json');
echo json_encode(['error' => 'Moved Permanently']);
Check the status with curl
curl -I https://example.com/resource
# Look for: HTTP/1.1 301 Moved Permanently
Frequently Asked Questions
What does HTTP 301 Moved Permanently mean?
All future requests should use the new URL provided in the Location header. In short: The resource has been permanently moved to a new URL.
How should I handle an HTTP 301 Moved Permanently response?
Update internal links to new URL. Use for permanent URL changes. Set Location header.
Official Specification
The 301 Moved Permanently status code is defined in RFC 7231 Section 6.4.2.