Sub topic 6
Changing a slug safely with 301 redirects
This chapter assumes you know what a slug is and how to write a good one. It also assumes you can read basic server configuration and understand HTTP status codes. Here you will learn how to change a slug without losing the visitors, links, and search signals the old URL has earned.
Why a slug change is risky
A URL is the address search engines have stored for your page. Other sites link to it, readers bookmark it, and search results point to it. If you rename the slug and do nothing else, the old address returns a 404 (not found) error. Visitors land on an error page, and the page's history is not connected to the new address.
The best slug is one you never change. Change one only when the old one is misleading, badly formed, or harming the site, not for small stylistic reasons.
What a 301 redirect does
A 301 is an HTTP response that says "this page has moved permanently". The server sends it with a Location header holding the new URL. Browsers follow it automatically, and search engines treat the new URL as the replacement for the old one. The old address passes its visitors and signals to the new one.
Setting up the redirect
In nginx, a single exact-match rule is enough for one page:
server {
listen 80;
server_name example.com;
# Permanently redirect the old slug to the new one
location = /blog/seo-tips-2019 {
return 301 /blog/internal-linking-tips;
}
}The = makes the rule match only that exact path. Without it, nginx would match any path that begins with those characters. Other servers and CMS plugins have equivalent features, but the response must still be a 301.
A safe procedure
- Choose the new slug and confirm it is not already used by another page.
- Publish the page at the new URL.
- Add the 301 from the old URL to the new URL. Send it directly to the final address.
- Update every internal link to use the new URL.
- Update the canonical tag, the XML sitemap, and any navigation to the new URL.
- Test the redirect, then keep it in place.
Step 4 matters even though the redirect works. Each internal link that still points at the old URL makes every visitor and crawler take an extra request. It also leaves the old address looking like the page you want indexed.
Verifying the result
Check the response headers rather than trusting the browser, which may cache redirects:
curl -I https://example.com/blog/seo-tips-2019The output should show 301 and a Location header with the new URL. Then request the new URL and confirm it returns 200.
Common mistakes
| Mistake | Effect | Fix |
|---|---|---|
| Using 302 for a permanent move | A 302 means "temporary", so search engines may keep the old URL | Use 301 (or 308) for permanent moves |
| Redirecting to the home page | Visitors lose the context of what they wanted | Redirect to the closest equivalent page |
| Chaining redirects (A to B to C) | Extra requests slow crawling | Point every old URL straight to the final one |
| Removing the redirect after a few weeks | Old links and bookmarks break again | Keep it for as long as the old URL has any links |
| Leaving internal links on the old URL | Needless redirect hops on every visit | Update the links in your content |
Exercise
Exercise
You renamed /blog/post-1 to /blog/url-slug-guide and added a 301 from the old address. Later you rename it again to /blog/writing-url-slugs. Which redirect rules should exist afterwards, and what else should you update?
Show answer
Both /blog/post-1 and /blog/url-slug-guide should send a 301 directly to /blog/writing-url-slugs, so no request goes through more than one hop. Update the internal links, canonical tag, and sitemap entry to /blog/writing-url-slugs. Then check with curl -I that each old URL returns a single 301 and the new URL returns 200.