🔗URL & UTM
301 vs 302 Redirects
Understanding permanent (301) vs temporary (302) URL redirects
Explanation
301 redirects are permanent and transfer SEO value. 302 redirects are temporary and don't pass full SEO value.
Examples
301 Permanent
Input
Old page permanently moved
Output
Search engines update index, pass link juice
302 Temporary
Input
Temporary maintenance or A/B test
Output
Search engines keep original URL in index
Code Examples
JavaScript
// Express.js redirects
app.get('/old-page', (req, res) => {
// 301 Permanent redirect
res.redirect(301, '/new-page');
});
app.get('/temp-page', (req, res) => {
// 302 Temporary redirect (default)
res.redirect('/other-page');
// or explicitly: res.redirect(302, '/other-page');
});
// Next.js redirects (next.config.js)
module.exports = {
async redirects() {
return [
{
source: '/old-blog/:slug',
destination: '/blog/:slug',
permanent: true // 301
},
{
source: '/temp',
destination: '/new',
permanent: false // 302
}
]
}
} Nginx
# Nginx configuration
# 301 Permanent redirect
location /old-page {
return 301 /new-page;
}
# 302 Temporary redirect
location /temp-page {
return 302 /other-page;
}
# Redirect with domain change
server {
server_name old-domain.com;
return 301 https://new-domain.com$request_uri;
} Apache
# Apache .htaccess
# 301 Permanent redirect
Redirect 301 /old-page /new-page
# 302 Temporary redirect
Redirect 302 /temp-page /other-page
# Using mod_rewrite
RewriteEngine On
RewriteRule ^old-page$ /new-page [R=301,L]
RewriteRule ^temp-page$ /other-page [R=302,L]Try it Now
💡 Tips
- Use 301 for permanent URL changes and SEO
- Use 302 for A/B tests and temporary moves
- Update internal links instead of relying on redirects
- Chain redirects hurt performance and SEO
- Test redirects don't create loops
- 307/308 preserve HTTP method (POST stays POST)
⚠️ Common Pitfalls
- Wrong redirect type hurts SEO
- Browsers cache 301s aggressively
- Redirect chains (A→B→C) are slow
- Too many redirects error (infinite loops)
- Mobile vs desktop redirect issues