301 vs 302 Redirects: How to Move Pages Without Losing Visitors
301 vs 302 redirects in plain words: when to use each, how to add them in .htaccess, WordPress or Cloudflare, and the mistakes that cost you visitors.
A redirect sends visitors and search engines from an old web address to a new one. Use a 301 redirect when a page has moved for good: a new URL, a merged page, a new domain or a switch to HTTPS. Use a 302 redirect only when the move is temporary and the old page will come back. Get it wrong, or skip redirects, and people land on error pages while search engines hold on to the old address. Here is the difference, and how to set redirects up in three common places.
What a redirect actually does
When a browser asks for a page, the server answers with a status code, a short number that says what happened. 200 means "here is the page". 404 means "not found". A code in the 300s means "this page lives somewhere else", along with the new address.
The browser follows it in a fraction of a second. Search engines follow it too, and the code tells them whether to update their records or keep the old address.
301 vs 302: permanent or temporary
- 301 Moved Permanently. The old address is retired. Google treats it as a signal that the new address should appear in search results, and over time the new page takes the old one's place.
- 302 Found (temporary). The page is elsewhere for now. Google does not treat a 302 as a sign that the new address should replace the old one, so the old URL usually stays in search results.
Two newer codes do the same jobs, with one difference: they keep the request method, so a submitted form keeps its data after the redirect. 308 is permanent and 307 is temporary. For ordinary pages, 301 and 302 work everywhere.
One warning: browsers can cache a 301, which makes it hard to undo. Use it only when the move is final.
When to use which
| Situation | Use |
|---|---|
| You renamed a page or changed its URL | 301 |
| You merged two pages into one | 301 from each old page |
| You moved to a new domain | 301 from every old URL to its new match |
| You are forcing HTTPS, or choosing www or non-www | 301 |
| A product is out of stock and you show a substitute for a while | 302 |
| A short campaign page replaces a page for a few weeks | 302 |
| A form posts to an address that has moved | 308 or 307 |
Take a bakery in Pristina moving from its old .com to a new domain, and merging its separate Albanian and English cake pages into one bilingual page. Each old page gets a 301 to its exact new page, not to the homepage. Customers with old bookmarks land in the right place, and search engines learn where the content went.
How to add redirects in three places
1. The .htaccess file on Apache
On Apache servers, a file called .htaccess in your site's main folder can hold redirect rules. Edit it through your control panel's file manager or over FTP, and keep a copy of the original. This example sends two old pages to new addresses, then sends everything else to HTTPS with www:
RewriteEngine On
# Single pages first, straight to the final address
RewriteRule ^old-cakes/?$ https://www.example.com/cakes/ [R=301,L]
RewriteRule ^about-us-sq/?$ https://www.example.com/about/ [R=301,L]
# Then HTTPS and www for everything else
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L]
Replace example.com with your domain. The page rules come first and point to the full final address, so visitors make one hop, not two. Plesk can also switch on the HTTPS redirect for you in the domain's Hosting Settings. Use one method, not both.
2. A WordPress redirect plugin
On WordPress, a redirect plugin saves you from editing files. Most work the same way: enter the old path, the new address and the redirect type, then save. Many also log 404 errors, so you can spot old links that still need a redirect. Use one redirect plugin, and don't repeat rules that already sit in .htaccess.
3. Cloudflare redirect rules
If your domain runs through Cloudflare, you can create redirect rules in its dashboard. A rule matches requests, for example everything on an old domain, and sends them to a new address with a 301 or 302. This happens before the request reaches your server, which is handy for retiring an old domain.
Common redirect mistakes
- Redirect chains. A goes to B, then B goes to C. Each hop slows the visitor down, and search engines may stop following long chains. Point every old URL straight to its final address.
- Redirect loops. A goes to B and B goes back to A, and the browser shows a "too many redirects" error. A common cause is an HTTPS rule set in two places. Our knowledgebase explains how to find and fix it.
- Sending everything to the homepage. Visitors lose the page they wanted, and Google may treat these redirects as missing pages (soft 404s). Match each old page to its closest new page. If nothing fits, a 404 is more honest.
- Forgetting internal links and the sitemap. Redirects are a safety net, not a fix. Update menus, buttons and links in your posts, and make sure your sitemap lists only the new addresses.
- Removing redirects too soon. Old links live on in other websites, emails and printed flyers. Google suggests keeping redirects for at least a year.
Checklist for a domain change
- Back up your files and database.
- List every old URL, for example from your sitemap, and the new URL for each.
- Set up the new domain with an SSL certificate so HTTPS works from day one.
- Add a 301 from each old URL to its exact new match.
- Test old URLs in a private browser window. Each should take one hop to the right page.
- Update internal links, the sitemap, email signatures and business profiles.
- Tell search engines about the move in their webmaster tools and submit the new sitemap.
- Keep the old domain registered and the redirects running for at least a year.
Moving to Zebra Hosting without breaking links
If a new host is part of your change, our team moves your website, databases and email for free on shared, WordPress and reseller plans. We test on a preview link first, there is no downtime, and you switch DNS last, when you are happy. It usually takes 1 to 2 business days. See how free migration works.