HTTP 301 Moved Permanently — When and How to Use Redirects

Learn when to use HTTP 301 Moved Permanently vs 302 Found vs 307 Temporary Redirect. Understand SEO implications, redirect chains, and implementation in Nginx, Apache, and application code.

HTTP Status Codes

Detailed Explanation

HTTP 301 Moved Permanently

A 301 redirect tells clients (browsers and search engines) that a resource has permanently moved to a new URL. All future requests should use the new URL.

301 vs 302 vs 307 vs 308

Code Meaning Method SEO
301 Moved Permanently May change to GET Passes full link equity
302 Found (Temporary) May change to GET Minimal link equity transfer
307 Temporary Redirect Preserves method Minimal link equity transfer
308 Permanent Redirect Preserves method Passes full link equity

When to Use 301

  • Domain migration — Moving from old.com to new.com
  • URL restructuring — Changing /blog/post-123 to /articles/post-title
  • Protocol upgrade — Redirecting HTTP to HTTPS
  • Trailing slash normalization/about/ to /about or vice versa
  • www to non-wwwwww.example.com to example.com

Redirect Chains

A redirect chain occurs when URL A redirects to B, which redirects to C. Each hop adds latency and search engines may stop following after 3-5 hops. Always redirect directly to the final URL.

Implementation

Nginx:

server {
    return 301 https://new-domain.com$request_uri;
}

Apache (.htaccess):

Redirect 301 /old-page https://example.com/new-page

Next.js (next.config.js):

module.exports = {
  redirects: async () => [
    { source: '/old', destination: '/new', permanent: true }
  ]
};

Use Case

Properly implementing 301 redirects during a website migration, URL restructuring, or domain change is critical for preserving search engine rankings. Incorrect redirects can cause loss of organic traffic, broken backlinks, and poor user experience. Understanding redirect chains, loop detection, and the difference between 301 and 308 is essential for web operations.

Try It — Error Code Reference

Open full tool