HTTP

Status Code

HTTP 301 Moved Permanently: Permanent Redirect

Learn what 301 redirect means, when to use it vs 302, and how to implement permanent redirects for SEO and URL changes.

3 min read beginner Try in Playground

TL;DR: 301 means “this URL has permanently moved.” Update your bookmarks—the old URL won’t come back.

What is 301 Moved Permanently?

A 301 redirect tells clients the resource has permanently moved to a new location. Browsers cache this and go directly to the new URL next time.

GET /old-page HTTP/1.1
Host: example.com
```text

```http
HTTP/1.1 301 Moved Permanently
Location: https://example.com/new-page

The browser automatically follows the Location header.

When to Use 301

  • Domain change - Moving from old-domain.com to new-domain.com
  • URL restructure - /blog/123/posts/my-article
  • HTTPS migration - HTTP → HTTPS
  • Removing www - www.example.com → example.com
  • Trailing slash normalization - /page//page

301 vs 302 vs 307 vs 308

CodeTypeMethod ChangeUse Case
301PermanentMay changePermanent URL change
302TemporaryMay changeTemporary redirect
307TemporaryPreservedTemporary, keep POST
308PermanentPreservedPermanent, keep POST

For most permanent redirects, use 301. If preserving POST method matters, use 308.

Implementation

Nginx

# Single redirect
location = /old-page {
    return 301 /new-page;
}

# HTTP to HTTPS
server {
    listen 80;
    return 301 https://$host$request_uri;
}

# www to non-www
server {
    server_name www.example.com;
    return 301 https://example.com$request_uri;
}
```text

### Express.js

```javascript
// Single redirect
app.get('/old-page', (req, res) => {
  res.redirect(301, '/new-page')
})

// Redirect middleware
app.use((req, res, next) => {
  if (req.hostname === 'www.example.com') {
    return res.redirect(301, `https://example.com${req.url}`)
  }
  next()
})

Apache (.htaccess)

# Single redirect
Redirect 301 /old-page /new-page

# HTTP to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
```text

## SEO Considerations

1. **301 passes link equity** - Search engines transfer ranking signals
2. **Browsers cache 301** - Reduces server load
3. **Update internal links** - Don't rely solely on redirects
4. **Avoid redirect chains** - A → B → C hurts performance
5. **Submit new sitemap** - Help search engines discover changes

## Common Mistakes

```javascript
// ❌ Wrong: Using 302 for permanent changes
res.redirect('/new-page') // Defaults to 302

// ✅ Correct: Explicit 301
res.redirect(301, '/new-page')
# ❌ Wrong: Redirect chain
/page1 → /page2 → /page3

# ✅ Correct: Direct redirect
/page1 → /page3
/page2 → /page3

301 redirects are the standard mechanism for preserving SEO value when changing URLs. Search engines treat 301 as a signal to transfer ranking signals (link equity, PageRank) from the old URL to the new URL. Google has stated that 301 redirects pass “full” link equity, though in practice there may be a small delay before the full transfer takes effect.

Redirect chains — where A redirects to B which redirects to C — dilute link equity and slow down page loads. Each hop in the chain adds latency and potentially loses some ranking signal. When restructuring URLs, always redirect directly to the final destination rather than through intermediate URLs. Audit your redirect chains periodically using tools like Screaming Frog or Ahrefs to identify and collapse multi-hop chains.

Browsers cache 301 redirects aggressively, sometimes indefinitely. If you need to change a redirect destination later, users who have the old redirect cached will continue going to the original destination until their cache expires or they clear it. For redirects that might need to change, consider using 302 initially and switching to 301 only when you are confident the destination is permanent.

Frequently Asked Questions

What does 301 redirect mean?

A 301 tells browsers and search engines the resource has permanently moved to a new URL. Update your bookmarks and links.

What is the difference between 301 and 302?

301 is permanent (update links, transfer SEO). 302 is temporary (keep original URL, check back later). Use 301 for permanent URL changes.

Does 301 pass SEO value?

Yes, 301 redirects pass most link equity (SEO value) to the new URL. Google treats 301 as a signal to index the new URL.

Can 301 change the request method?

Historically, some clients changed POST to GET on 301. Use 308 if you need to preserve the method. Modern browsers handle 301 correctly.

Keep Learning