1. Home
  2. Blog
  3. Software Development

Software Development

301 vs 302 Redirect: Differences, SEO Impact, 307 and 308

A 301 vs 302 redirect choice tells browsers and search engines whether a move is permanent or temporary. Learn what each status code means, how 307 and 308 differ by preserving the request method, what happens to POST data, how search engines treat each one, and why chains and loops hurt, with a local server we tested.

9 min read
301 vs 302 redirect: differences, SEO impact, 307 and 308

Key takeaways

  • The 301 vs 302 redirect difference is permanent versus temporary: 301 says “use the new URL from now on”, 302 says “go there for now”.
  • 307 and 308 are the strict versions of 302 and 301: they must keep the request method and body.
  • In our test, a POST to a 301 or 302 came back as a GET with an empty body; for 307 and 308 the Python client refused to redirect the POST at all.
  • Search engines consolidate signals to the target of a permanent redirect; use 301 or 308 for real moves.

You moved a page, changed a domain, switched to HTTPS or renamed a product URL. A redirect sends visitors and crawlers from the old address to the new one, but which status code you use decides how browsers cache it, how search engines index it and what happens to form submissions. Choosing between a 301 vs 302 redirect, and their newer siblings 307 and 308, takes one minute once you know the rules.

We built a small Python server (Python 3.13.6, standard library) that returns each redirect type, then called it with Python’s HTTP clients to see exactly what happens. Search engine behaviour comes from published documentation and widely reported tests, which we summarise rather than ran.

301 vs 302: the short answer

Aspect 301 302
Meaning Moved permanently Found elsewhere, temporarily
Browser caching Cached by default, often for a long time Not cached unless headers say so
Search engines Index the new URL, consolidate signals to it Usually keep the old URL indexed
Use for Page moves, domain changes, HTTPS, merged content Short promotions, A/B tests, maintenance pages

How a redirect works

raw GET /old-301: 301 Moved Permanently, Location: /target
raw GET /old-302: 302 Found, Location: /target
raw GET /old-307: 307 Temporary Redirect, Location: /target
raw GET /old-308: 308 Permanent Redirect, Location: /target

The server answers the original request with a 3xx status code and a Location header naming the new address. The client then makes a second request to that address. Our raw requests above show each server response before any client follows it. The status code is the only thing that differs between the four, and it carries two pieces of information: permanent or temporary, and whether the method must be preserved.

301 Moved Permanently

A 301 says the resource has a new permanent URL and clients should use it from now on. Browsers cache 301 responses aggressively, sometimes until the cache is cleared, so a wrong 301 can keep sending users to the wrong place long after you fix the server. Search engines treat the target as the canonical URL and transfer the old page’s ranking signals to it over time. Use 301 for permanent moves of pages and sites.

302 Found

A 302 says the resource is temporarily somewhere else, and the original URL remains the one to use in future. Browsers do not cache it by default. Search engines usually keep the original URL in their index, though if a 302 stays in place for a long time, they may start treating it like a permanent redirect. Use it for genuinely temporary situations: a seasonal landing page, a maintenance notice, a geo-based redirect or sending logged-out users to a sign-in page.

307 and 308: method-preserving redirects

Historically, browsers turned a POST into a GET when following 301 and 302 redirects, even though the original specification did not intend that. To remove the ambiguity, HTTP added two codes:

  • 307 Temporary Redirect: like 302, but the client must repeat the same method and body.
  • 308 Permanent Redirect: like 301, but the method and body must be preserved.

For ordinary page visits, which are GET requests, 307 behaves like 302 and 308 like 301. They matter for APIs and form submissions, where silently turning a POST into a GET loses data.

All four redirect codes compared

Code Permanent? Method and body kept? Typical use
301 Yes Not guaranteed (POST often becomes GET) Page and domain moves
302 No Not guaranteed Temporary page redirects
307 No Yes Temporary API redirects, HSTS upgrades in browsers
308 Yes Yes Permanent API endpoint moves

The other 3xx codes are less common: 303 See Other explicitly tells the client to fetch the target with GET (the classic redirect after a form submission), and 304 Not Modified is a caching response, not a redirect; see our HTTP caching guide.

What happens to a POST request

urllib POST /old-301 followed -> 200 {"path": "/target", "method": "GET", "body": ""}
urllib POST /old-302 followed -> 200 {"path": "/target", "method": "GET", "body": ""}
urllib POST /old-307 -> 307 Temporary Redirect
urllib POST /old-308 -> 308 Permanent Redirect

We posted qty=2 to each old URL using Python’s urllib. For 301 and 302, the client followed the redirect but switched to GET and dropped the body: the target received no order data. For 307 and 308, which forbid changing the method, urllib refused to follow automatically and returned the redirect as an error, leaving the decision to the caller. Browsers re-send the POST to the new URL for 307 and 308. Either way, the lesson for APIs is clear: if an endpoint that receives POST, PUT or DELETE moves, use 307 or 308, and better still, update clients to call the new URL directly. Our HTTP methods guide covers why methods matter.

SEO impact of 301 vs 302

  • Indexing: after a 301 or 308, search engines replace the old URL with the target in results. After a 302 or 307 they typically keep the old URL.
  • Link signals: Google has said that redirects of any type no longer lose PageRank, but a permanent redirect is the clearest signal that signals should consolidate on the new URL.
  • Long-lived 302s: if a temporary redirect never goes away, search engines may eventually treat it as permanent, but relying on that is guesswork. Use the right code from the start.
  • Internal links: after a move, update your own links to point at the new URL; redirects are a safety net, not a substitute.
  • Canonical tags and sitemaps: list only final URLs in sitemaps, and make canonical tags point to the redirect target.

A domain or HTTPS migration also involves DNS changes; see our DNS records guide.

Redirect chains and loops

chain of 3 followed -> /target 200
redirect loop -> 301 HTTP Error 301: The HTTP server returned a redirect error that would lead to an infinite loop

A chain is a redirect to a redirect: /chain1 to /chain2 to /chain3 to /target. Our client followed it, but each hop costs a full round trip, slows the page and dilutes crawl budget. Crawlers stop following after a limit, around ten hops for Google. A loop, where A redirects to B and B back to A, never resolves; the Python client detected it and gave up, and browsers show an error page. Both usually appear after several migrations stack up. Point every old URL straight at its final destination.

Tip: after any migration, crawl your old URL list and confirm each one reaches a 200 in exactly one hop.

Which redirect to use when

Situation Code
Page URL changed for good 301
HTTP to HTTPS, or www to non-www 301 (or 308)
Domain migration 301
Merged two articles into one 301 to the merged page
Temporary promotion or maintenance page 302 or 307
Redirect after a successful form POST 303
API endpoint moved permanently 308
API endpoint temporarily elsewhere 307

Setting up redirects

# nginx
location = /old-page { return 301 /new-page; }

# Apache (.htaccess)
Redirect 301 /old-page /new-page

Server-level redirects are fastest and work for every client. Most CMSs and SEO plugins can manage redirects in their admin screens too. Avoid JavaScript or meta refresh redirects for permanent moves; they are slower and less reliable signals. We did not run the nginx and Apache examples here. For URLs with special characters, our URL encoding guide helps avoid broken targets.

Testing redirects

  • Use curl -I https://example.com/old-page to see the status code and Location without following.
  • Check that each old URL reaches the final page in one hop with a 200.
  • Test POST endpoints separately if APIs are involved.
  • Remember browsers cache 301s; test in a private window after changes.
  • Monitor 404s after a migration to catch missed URLs, and see the status codes cheat sheet for other responses.

Final thoughts

The 301 vs 302 redirect decision is about intent: permanent moves get 301, or 308 for APIs that must keep their method; temporary detours get 302, or 307 for APIs. Our tests showed why the method-preserving codes exist, as 301 and 302 turned a POST into an empty GET. Point old URLs straight at their final destination, avoid chains and loops, update internal links, and your users, crawlers and API clients will all end up in the right place.

Frequently asked questions

What is the difference between a 301 and 302 redirect?

A 301 redirect is permanent and tells browsers and search engines to use the new URL from now on. A 302 is temporary, so the original URL stays the one to use and index.

Is 301 or 302 better for SEO?

For permanent moves, 301 is the right choice because search engines index the new URL and consolidate signals to it. Use 302 only for genuinely temporary redirects.

What is the difference between 302 and 307?

Both are temporary. A 307 requires the client to repeat the same method and body, while a 302 may let clients change a POST into a GET.

When should I use a 308 redirect?

Use 308 when a resource has moved permanently and the request method must be preserved, such as an API endpoint that receives POST or PUT requests.

How many redirects are too many?

Aim for one hop from the old URL to the final page. Each extra hop slows loading, and crawlers stop after a limited number of redirects in a chain.

Keep learning

Work with Stack Quora

Need help with testing, WordPress or SEO?

We help teams ship better software and grow their sites. Tell us what you are working on and we will suggest a clear next step.

Keep reading

More guides on testing, AI & modern development

Enjoyed this article? Pick a topic and jump straight into our newest tutorials.

Artificial Intelligence

Confusion Matrix Explained: Precision, Recall, F1 and Thresholds in Python

Confusion matrix explained with Python: TP, FP, FN, TN, precision, recall, F1, the accuracy trap, threshold choice by cost and…

Read article →
Software Development

API Pagination: Offset vs Cursor vs Keyset, Tested on 1 Million Rows

API pagination explained: offset vs keyset and cursor pagination timed on 1 million rows, duplicates when data changes, the ties…

Read article →
DevOps

Git Submodule Explained: Add, Clone, Update and Remove Safely

Git submodule explained: add, clone, update –init, update –remote, the detached HEAD trap, foreach and clean removal, tested step by…

Read article →
Test Automation

Pytest tmp path Explained: tmp_path, tmp_path_factory and Temp Files

Pytest tmp_path explained: per-test temporary folders, tmp_path_factory for shared files, monkeypatch.chdir, legacy tmpdir, retention and basetemp.

Read article →
Software Testing

Test Case Prioritization: 6 Techniques Compared With APFD

Test case prioritization compared: risk, coverage, cost, history and random orders scored with APFD and time to find all faults…

Read article →
Databases & SQL

Full Text Search in SQL: FTS5, Ranking, Phrases and Speed

Full text search in SQL with SQLite FTS5: MATCH queries, phrases, prefixes, NEAR, stemming, BM25 ranking, snippets, two gotchas and…

Read article →
Databases & SQL

Generated Columns in SQL: Virtual vs Stored, Indexes and Limits

Generated columns in SQL explained: virtual vs stored, automatic updates, write errors, storage cost, indexing, JSON fields and support in…

Read article →
Software Development

Object Freeze in JavaScript: Shallow vs Deep, Seal and const

Object freeze in JavaScript explained: freeze vs seal vs const, strict mode errors, shallow vs deep freeze, frozen arrays, Map…

Read article →
Software Development

Python hashlib: SHA-256, File Hashes, HMAC and Password Hashing

Python hashlib explained: SHA-256 for strings and files, algorithm speeds, why passwords need PBKDF2 or scrypt, safe verification and HMAC…

Read article →
Software Development

Python UUID Explained: uuid1, uuid4, uuid5, uuid7 and Database Keys

Python UUID explained: uuid4, uuid5, uuid1 privacy, time-ordered uuid7, parsing, storage formats and UUIDs as database keys, tested on Python…

Read article →
Artificial Intelligence

Random Forest in Python: Bagging, Feature Sampling and OOB From Scratch

Random forest in Python from scratch: bootstrap sampling, feature sampling, number of trees, out-of-bag evaluation and impurity vs permutation importance.

Read article →
Software Development

MIME Types Explained: Content-Type, nosniff and a Common Types List

MIME types explained and tested in a browser: Content-Type, nosniff, scripts and stylesheets with wrong types, a common MIME types…

Read article →
DevOps

Git Clean Explained: Remove Untracked Files Without Regret

Git clean explained with dry runs: -n, -f, -d, -x, -X, exclusions, paths, nested repositories and interactive mode, plus a…

Read article →
Test Automation

Pytest approx: Comparing Floats With rel, abs and Collections

Pytest approx explained: default tolerances, the near-zero trap, rel and abs, lists and dicts, NaN, NumPy, and how it differs…

Read article →
Software Testing

Accessibility Testing: WCAG Checklist, Automated Tools and Manual Checks

Accessibility testing explained: WCAG basics, an axe-core scan of a broken and a fixed page, what automation missed, contrast checks…

Read article →
Databases & SQL

SQL UNPIVOT: Turn Columns Into Rows, 4 Ways Tested

SQL UNPIVOT explained: turn columns into rows with UNION ALL, CROSS JOIN with CASE, JSON functions or native UNPIVOT, with…

Read article →
Software Development

Intl NumberFormat in JavaScript: Currency, Compact, Percent and Units

Intl.NumberFormat in JavaScript: locales, currency, compact notation, percent, units, rounding, formatToParts, the non-breaking space trap and formatter reuse.

Read article →
Databases & SQL

SQL EXPLAIN Plan: How to Read Query Plans and Fix Slow Queries

SQL EXPLAIN plan explained: read scans, index searches, covering indexes and temporary sorts, with before and after timings for five…

Read article →
Artificial Intelligence

Decision Tree in Python: Gini, Entropy and Overfitting From Scratch

Decision tree in Python from scratch: Gini impurity, entropy, information gain, best splits, readable rules, and how depth and leaf…

Read article →
DevOps

Git Blame Explained: Find Who Changed a Line, and Why

Git blame explained with a real repository: ignore whitespace, line ranges and functions, ignore-revs files for formatting commits, moved code…

Read article →
Test Automation

Pytest Benchmark: Measure Speed and Catch Performance Regressions

Pytest benchmark tutorial: the benchmark fixture, reading results, parametrized and pedantic benchmarks, saving baselines and failing the build on regressions.

Read article →
Software Testing

Defect Density: Formula, Worked Examples and How to Use It

Defect density explained: the formula, a five-module worked example, per KLOC vs per function point, severity weighting, defect removal efficiency…

Read article →
Databases & SQL

Case Insensitive Search in SQL: LOWER, LIKE, COLLATE and Indexes

Case insensitive search in SQL: LOWER, LIKE, COLLATE NOCASE and expression indexes compared with query plans, plus accented letters and…

Read article →
Databases & SQL

ON DELETE CASCADE in SQL: CASCADE vs SET NULL vs RESTRICT

ON DELETE CASCADE in SQL tested: CASCADE vs SET NULL vs RESTRICT, multi-level cascades, the SQLite foreign key pragma, row…

Read article →
Artificial Intelligence

Logistic Regression in Python: Sigmoid, Log Loss and Gradient Descent From Scratch

Logistic regression in Python from scratch: sigmoid, log loss, gradient descent, odds ratios, thresholds, sigmoid overflow and separable data, tested…

Read article →
DevOps

Git Worktree Explained: Work on Two Branches at Once

Git worktree explained: add, list, remove, prune, lock and detached worktrees, a hotfix workflow, and the errors you will hit,…

Read article →
Test Automation

Pytest ini Explained: addopts, markers, testpaths and Precedence

Pytest ini explained: testpaths, addopts, strict markers, xfail_strict, filterwarnings, minversion, config file precedence and command-line overrides, tested.

Read article →
Software Testing

Test Estimation Techniques: WBS, Three Point PERT and Monte Carlo

Test estimation techniques worked through: WBS, three point PERT, total uncertainty, a Monte Carlo check, percentage rules and Wideband Delphi.

Read article →
Artificial Intelligence

Linear Regression in Python: Least Squares From Scratch, With R Squared

Linear regression in Python from scratch: closed form, NumPy least squares and gradient descent, R squared, RMSE, outliers and curved…

Read article →
DevOps

Git Remote Explained: Add, Set-URL, Rename, Remove and Push URLs

Git remote explained: add, set-url, separate push URLs, rename, remove and prune, plus how to avoid leaking tokens in remote…

Read article →
Test Automation

Pytest Mock: mocker.patch, spy, side_effect and autospec Explained

Pytest mock explained: mocker.patch, return_value, side_effect, spy, autospec and PropertyMock, with tested examples for APIs, clocks and retries.

Read article →
Software Testing

System Testing Explained: Types, Process and a Real End-to-End Example

System testing explained: types, entry and exit criteria, the process, and a real end-to-end test suite run against a small…

Read article →
Artificial Intelligence

Naive Bayes Classifier Explained: Build a Spam Filter in Python

Naive Bayes classifier explained by building a spam filter in Python: Bayes rule, the naive assumption, Laplace smoothing, log probabilities…

Read article →
DevOps

Git Branch Explained: Create, Switch, Rename, Delete and Recover

Git branch explained with tested commands: list, create, switch, rename, delete, merged checks, recovering deleted branches, remote tracking and naming.

Read article →
Test Automation

Pytest raises: Testing Exceptions, match and excinfo

Pytest raises explained with tested examples: match regexes, excinfo, custom and chained exceptions, parametrized error cases, pytest.warns and common mistakes.

Read article →
Software Testing

Non Functional Testing: Types, Metrics and a Real Load Test

Non functional testing explained: 10 key types, measurable requirements, latency percentiles and what a small real load test revealed about…

Read article →