
A 301 redirect tells browsers and search engines that a page has moved permanently, so Google should index the new address and pass its ranking signals there. A 302 redirect means the move is temporary and the old URL should stay in the index. Then use 301 for changed URLs, site migrations, HTTP to HTTPS and www changes; use 302 only for short-term moves. Also, this guide explains every redirect code, shows working examples for Apache, Nginx, PHP and WordPress, and covers the mistakes that cost sites their traffic. In addition, this guide explains 301 vs 302 redirect step by step.
- 301 and 308 are permanent; 302 and 307 are temporary. Google treats long-lived 302s as permanent eventually, but do not rely on that.
- Redirect each old URL to its closest new equivalent, not everything to the home page.
- Avoid chains (A → B → C) and loops. Each old URL should reach its final page in one hop.
- Keep migration redirects in place for at least a year, ideally permanently.
301 vs 302 redirect: redirect status codes compared
| Code | Meaning | Method kept? | Use it for |
|---|---|---|---|
| 301 | Moved permanently | Browsers may change POST to GET | Changed URLs, migrations, HTTPS and www rules |
| 308 | Permanent redirect | Yes | Permanent moves for APIs or forms that must keep POST |
| 302 | Found (temporary) | Browsers may change POST to GET | Short promotions, A/B tests, maintenance pages |
| 307 | Temporary redirect | Yes | Temporary moves that must keep the method; also used internally by browsers for HSTS |
| Meta refresh / JS | Client-side redirect | Not applicable | Last resort when you cannot configure the server |
For SEO, Google says 301 and 308 are strong signals that the target should become the canonical URL, while 302 and 307 are weaker. If you see a 307 Internal Redirect in Chrome DevTools on an HTTPS site, that is usually the browser applying HSTS, not your server.
301 vs 302 redirect: when to use a 301
- You changed a page's slug, for example
/services/webto/web-development. - Also, you moved to a new domain or merged two websites.
- You switched from HTTP to HTTPS (see our SSL guide).
- Also, you standardised on www or non-www.
- You deleted a product or post that has a close replacement.
- You merged several thin articles into one stronger guide.
301 vs 302 redirect: when a 302 is the right choice
- A product is out of stock for a week and you send visitors to a category page.
- A seasonal page, such as an Eid sale, temporarily replaces the normal offers page.
- You are sending visitors to a maintenance page during a short update.
- Geo or language detection that should not replace the original URL in the index.
301 vs 302 redirect: how to set up redirects on Apache (.htaccess)
In fact, most shared hosting in Pakistan, including cPanel and Hostinger plans, runs Apache or LiteSpeed, which read .htaccess rules. Always back up the file before editing it, because a typo can cause a 500 error. Also, this matters for 301 vs 302 redirect on every kind of site.
Single page:
Redirect 301 /old-page /new-page
Force HTTPS and www in one hop:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,R=301]
Move a whole folder:
RewriteEngine On
RewriteRule ^blog/2024/(.*)$ /blog/$1 [L,R=301]
Move a whole domain to a new one, keeping paths:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?oldbrand\.pk$ [NC]
RewriteRule ^(.*)$ https://www.newbrand.com/$1 [L,R=301]
Put redirect rules above the WordPress or framework rewrite block, otherwise they may never run.
301 vs 302 redirect: how to set up redirects on Nginx
# Single page
location = /old-page { return 301 /new-page; }
# Force HTTPS and www
server {
listen 80;
server_name example.com www.example.com;
return 301 https://www.example.com$request_uri;
}
# Folder move with regex
rewrite ^/blog/2024/(.*)$ /blog/$1 permanent;
Run nginx -t to test the configuration before reloading the server.
301 vs 302 redirect: how to redirect in PHP
<?php
header('Location: https://www.example.com/new-page', true, 301);
exit;
The header() call must run before any HTML is printed, and exit stops the rest of the page from loading.
How to manage redirects in WordPress
- Redirection plugin (free): add 301s from the dashboard, log 404s and turn the useful ones into redirects.
- Rank Math or Yoast Premium: include redirect managers and can create a redirect automatically when you change a slug.
- Large lists: for hundreds of URLs from a migration, server-level rules in
.htaccessor Nginx are faster than a plugin, because they run before WordPress loads.
WordPress itself redirects some changed post slugs automatically, but do not depend on it for important pages.
Redirect map for a site migration
Also, when you redesign or move platforms, URL changes are the biggest cause of lost traffic. Plan redirects before launch:
- Export every old URL from your sitemap, Search Console (Pages and Performance reports), Google Analytics and a crawler such as Screaming Frog.
- Map each one to its closest new URL in a spreadsheet with two columns: old path and new path.
- Prioritise pages with backlinks, traffic or conversions. These must map one-to-one.
- Implement the rules on the staging site and crawl the old URL list to confirm every one returns a single 301 to a 200 page.
- Update internal links to point straight at new URLs, so visitors and crawlers do not depend on redirects.
- Submit the new sitemap in Search Console and use the Change of Address tool if the domain changed.
- Monitor 404s and indexing for at least eight weeks after launch.
How to test a redirect
Do not trust the browser alone, because browsers cache 301s aggressively. Test from the command line:
curl -I http://example.com/old-page
The response should show HTTP/1.1 301 Moved Permanently and a Location: header with the final URL. Add -L to follow the chain and count the hops. Browser extensions such as Redirect Path, or the Network tab in DevTools with "Preserve log" ticked, also show every step.
Common redirect mistakes
- Redirect chains: HTTP → HTTPS → www → new slug. Combine them into one rule.
- Redirect loops: two rules sending traffic back and forth, which shows as "too many redirects" in the browser.
- Using 302 for permanent moves: common with some plugins and hosting panels. Check the actual status code.
- Redirecting everything to the home page: loses the relevance of the old pages.
- Removing redirects too early: old backlinks and bookmarks keep sending visitors for years.
- Canonical tags and sitemaps still listing old URLs: send mixed signals to Google.
Frequently asked questions
Do 301 redirects lose SEO value?
Google has confirmed that 301, 302 and other server-side redirects no longer lose PageRank. The bigger risk is redirecting to an unrelated page, which Google may ignore.
How long should I keep a 301 redirect?
Google recommends at least one year. In practice, keep important redirects permanently, since they cost almost nothing.
Can I change a 302 to a 301 later?
Yes. Change the rule on the server; Google will pick up the permanent signal on its next crawl.
Why does my browser still show the old redirect after I removed it?
Browsers cache 301 responses. Test in a private window or with curl, and clear the browser cache.
Related guides: ERR_TOO_MANY_REDIRECTS, Why Website Speed Matters and How to Make Your Site Faster and How to Get Your Website on Google.
For official guidance, see Google Search Central.
Planning a redesign or migration?
We build full redirect maps and test them before launch, so you keep your rankings when you move. See our web development and SEO services, or contact us for a migration plan.
Written by the ItsWebExpert team, a web design and development company in Karachi building websites, online stores and apps for businesses across Pakistan.
Ask a Question on WhatsApp