---
title: "Use the right redirect code · Agent Wranglers"
url: https://agentwranglers.se/playbook/website/redirects-and-canonicals/redirect-codes
updated: 2026-10-20
licence: "All rights reserved"
---

# Use the right redirect code

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Required
- Chapter: [Redirects and canonicals](https://agentwranglers.se/playbook/website/redirects-and-canonicals)
- Rule: Use a server-side permanent redirect (301 or 308) for anything that moved for good. Use 302 or 307 only for short-term moves, and 303 only to show a result page after a form post.
- How: Permanent redirects tell search engines the new address is canonical. Temporary ones keep the old address in results. Use 308 or 307 when a form or API must keep its method and body. Browsers may turn a 301 or 302 POST into a GET. Redirect once. Fix trailing slash, case, `index.html`, `www` and `http` together, and keep the query string. Googlebot follows at most 10 hops, and every hop costs a round trip. Browsers may cache a 301 for good, so send `Cache-Control: max-age=86400` on it until you are sure the target is right.
- Check: `curl -sI` on an old address shows 301 or 308 and a `location` header with the final address. `curl -sIL` shows at most one redirect before a 200.

Example:

```http
HTTP/2 301
location: https://example.com/guides/new-name
```

```nginx
# http and www go straight to the final host in one hop
server {
  listen 80;
  server_name example.com www.example.com;
  return 301 https://example.com$request_uri;
}
server {
  listen 443 ssl;
  server_name www.example.com;
  ssl_certificate     /etc/ssl/example.com/fullchain.pem;
  ssl_certificate_key /etc/ssl/example.com/privkey.pem;
  return 301 https://example.com$request_uri;
}
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers website playbook: https://agentwranglers.se/playbook/website/redirects-and-canonicals/redirect-codes`.

- Previous: [Link only to final addresses](https://agentwranglers.se/playbook/website/redirects-and-canonicals/final-addresses)
- Next: [Avoid meta refresh and JavaScript redirects](https://agentwranglers.se/playbook/website/redirects-and-canonicals/client-side-redirects)
- [Redirects and canonicals](https://agentwranglers.se/playbook/website/redirects-and-canonicals)
