Applies to: Apache 2.4, Nginx, PHP and WordPress (tested with Apache 2.4.68, Nginx 1.31.6 and PHP 8.3)

302 Found is a temporary redirect: the server tells the browser that the page is, for now, at another address (given in the Location header). Browsers follow it automatically, and search engines normally keep the original address in their results, because the move is temporary.

The redirect codes compared

  • 301 Moved Permanently: the page has moved for good. Use it for changed URLs and domain moves; search engines transfer the old page’s ranking to the new one.
  • 302 Found: temporary. Browsers may change a POST into a GET when they follow it.
  • 303 See Other: “go and GET this other page”, typically after a form is submitted.
  • 307 Temporary Redirect: temporary, and the method and body must stay the same (a POST stays a POST).
  • 308 Permanent Redirect: permanent, and keeps the method, like a 301 for APIs and forms.

Check what a URL returns

curl -sI https://example.com/old-page | grep -iE "^HTTP|^location"
curl -sIL https://example.com/old-page | grep -iE "^HTTP|^location"   # follow the whole chain

Where unwanted 302s come from

Many tools send a 302 unless you ask for something else. We confirmed each of these:

  • Apache: Redirect /old /new without a code answers 302 Found.
  • PHP: header('Location: /new'); answers 302 Found.
  • WordPress: wp_redirect() uses 302 by default.
  • Nginx: return 302 /new; shows as 302 Moved Temporarily (Nginx’s wording for the same code).
  • Frameworks: Laravel, for example, sends a browser back to the form with a 302 when validation fails.

Make a redirect permanent

# Apache (.htaccess)
Redirect 301 /old-page https://example.com/new-page

# Nginx
location = /old-page { return 301 https://example.com/new-page; }

# PHP
header('Location: https://example.com/new-page', true, 301);
exit;

In WordPress, the Redirection plugin lets you choose the code for each redirect: set up redirects in WordPress. More .htaccess examples: URL redirection.

When a 302 is the right choice

  • A page is briefly unavailable (maintenance, an out-of-stock product) and will come back.
  • Sending visitors to a language or country version, or to a login page.
  • Short tests of a new page before you make the change permanent.

If the move is permanent, use 301 (or 308): a long-lived 302 can keep the old address in search results. Moving a whole site: forward visitors to a new domain.

Ucartz services for this topic

Was this answer helpful? 0 Users Found This Useful (0 Votes)