error code 301

HTTP Status Code 301 = “Moved Permanently”

It means the requested resource has been permanently moved to a new URL.

The browser, search engines, and clients should use the new URL from now on.

Purpose

301 is mainly used for:

  • Website URL changes
  • Domain migration
  • HTTPS redirection
  • SEO redirects
  • Renamed pages/endpoints Example

Client requests

http id=”r2k8mv”
GET /old-page HTTP/1.1

Server responds

http id=”v5q1ne”
HTTP/1.1 301 Moved Permanently
Location: https://example.com/new-page

The browser automatically redirects to the new URL.

SEO importance

Search engines like Google transfer SEO ranking/link authority to the new page when using 301.

Common use cases

  • Redirect httphttps
  • Redirect old domain → new domain
  • Redirect /old-blog/new-blog
  • Remove www
  • API endpoint migration Apache .htaccess

apache id=”d9w2yt”
Redirect 301 /old-page https://example.com/new-page

Nginx

nginx id=”u7m4pc”
rewrite ^/old-page$ https://example.com/new-page permanent;

PHP

php id=”k3x8ra”
header(“Location: https://example.com/new-page”, true, 301);
exit;

Node.js Express

js id=”b5v9qe”
res.redirect(301, ‘/new-page’);

Laravel

php id=”n4p2zd”
return redirect(‘/new-page’, 301);

Difference between 301 and 302

| Code | Meaning | Permanent |
| — | | |
| 301 | Moved Permanently | ✅ |
| 302 | Temporary Redirect | ❌ |

Use 301 only when the move is permanent.

Related redirect codes

CodeMeaning
300Multiple Choices
301Moved Permanently
302Found / Temporary Redirect
303See Other
307Temporary Redirect
308Permanent Redirect