Lesson 21 / 32
Redirects & 404 Handling
Manage page moves and deletions without losing SEO value.
Redirect status codes
301 (Permanent) tells search engines the page moved permanently; links juice transfers to the new URL. 302 (Temporary) means the old page might come back; juice doesn't fully transfer. Always use 301 for permanent moves.
Redirect examples
Implement redirects at the server level for best performance. Redirect chains (A→B→C) are slower; avoid them.
# Nginx example: Permanent 301 redirect
server {
listen 80;
server_name old-domain.com;
# Redirect entire domain
return 301 https://new-domain.com$request_uri;
}
# Redirect single page
server {
listen 80;
server_name example.com;
# Old page moved
location = /old-article.html {
return 301 https://example.com/blog/new-article/;
}
# Remove trailing slash
location ~ ^(.*)/$
{
return 301 $scheme://$server_name$1;
}
}Handling 404 pages
Return a true 404 status code for pages that don't exist. Don't redirect to homepage or return 200 OK; crawlers will think the page exists. Create a helpful 404 page with navigation and suggestions.
Canonicalization vs redirects
Canonical tags handle duplicate content; redirects handle moved pages. Use canonical for variants of the same content (www vs non-www), redirects for permanent page moves.
Monitor redirect chains
A→B→C chains slow down crawlers. Check your redirects quarterly and fix chains. Test with curl or DevTools to ensure responses are HTTP 301/302, not meta refreshes.