A redirect sends visitors and crawlers from one URL to another automatically. The server answers a request with a status code in the 300 range and a new address. Permanent redirects (301, 308) tell search engines the move is lasting. Temporary ones (302, 307) say the original will return.
How does a redirect work?
When a browser asks for a URL, the server can reply with a redirect instead of a page. MDN explains that redirect responses have status codes that start with 3 and a Location header holding the new address. The browser then requests that address. The visitor sees the new page and the address bar changes.
Which redirect codes exist?
| Code | Meaning | Use it when |
|---|---|---|
| 301 | Moved permanently | A page has a new URL for good |
| 308 | Permanent redirect, method kept | Same as 301, but form posts or API calls must keep their method |
| 302 | Found (temporary) | The move is short term, such as a maintenance page |
| 307 | Temporary redirect, method kept | Same as 302, with the method preserved |
For ordinary web pages fetched with GET, 301 and 308 behave the same for search, and so do 302 and 307. The difference matters for non-GET requests: MDN notes that a 308 keeps the method and body unchanged, while a 301 may turn other methods into GET. For a deeper comparison of the two most common codes, see 301 vs 302 redirect.
What does Google do with a redirect?
Google's documentation says that permanent redirects show the new target in search results, while temporary redirects keep showing the source page. Google recommends a permanent server-side redirect whenever possible when a URL changes, and says to use a permanent redirect only when you are sure the change will not be reversed.
Google also says it treats an instant meta refresh as a permanent redirect and a delayed one as temporary. It warns that JavaScript redirects are the least reliable, because rendering may fail and Google might never see the redirect.
When should you use a redirect?
- You changed a URL. Redirect the old address to the new one.
- You merged two pages. Redirect the removed page to the one that now holds its content.
- You moved to HTTPS or a new domain. Redirect every old URL to its exact equivalent.
- You pick one version of your site address. Redirect the www or non-www version to the other so only one exists.
Redirect to the closest matching page, not always the home page. Sending every old URL to the home page can be treated as a soft 404 by Google; see soft 404 errors.
What goes wrong with redirects?
- Chains. A to B to C wastes time and crawl effort. Point A straight to C. The fix is in how to fix redirect chains.
- Loops. A to B to A. The page never loads. Browsers show an error.
- Using a temporary code for a permanent move. Search engines may keep the old URL in results.
- Redirecting to an unrelated page. Visitors bounce, and search engines may ignore the redirect.
How do you check a redirect?
Run curl -I https://example.com/old-page in a terminal. Look at the first line for the status code and at the Location header for the target. You can then run it again on the target to make sure it answers 200 directly. For the setup side, see how to do a 301 redirect.
Frequently Asked Questions
Is a redirect the same as a canonical tag?
No. A redirect moves the visitor. A canonical tag leaves both pages reachable and hints which one to index.
Does a redirect hurt SEO?
A correct one does not. Chains, loops and redirects to unrelated pages cause problems.
Which code should I use by default?
Use 301 for permanent moves and 302 for short ones. Use 308 or 307 when non-GET requests are involved.
How long should I keep a redirect?
Keep it as long as the old URL gets visits or has links pointing to it. In practice that often means indefinitely.
Can I use JavaScript to redirect?
Only if you cannot do it on the server. Google says rendering may fail, so it can miss the redirect.