301 vs. 302 Redirects: How Search Engines Treat a URL Change, Measured on This Blog
Sooner or later every site changes a URL: a cleaner slug, a move to HTTPS, a new domain or subdomain. Each time, the same question comes up: should the redirect be a 301 or a 302? I covered HTTP status codes in general in " HTTP Status Code Basics ." This article narrows in on 301 and 302: how search engines interpret each one, and which redirects WordPress already sends on its own. The examples…
Every website change its URL sooner or later, such as a cleaner slug, moving to HTTPS, or switching to a new domain or subdomain. The question that arises each time is whether the redirect should be a 301 or a 302. This article focuses on these two HTTP status codes and how search engines interpret them, specifically in the context of WordPress.
A redirect has two parts: a status code indicating the nature of the move, and a Location header specifying the new URL. Both 301 and 302 appear identical to the visitor, as the browser follows the Location header regardless. The key difference lies in whether the move is intended to be permanent or temporary.
For ordinary page URLs visited with GET, a permanent change should use a 301 redirect, while a temporary change requires a 302 redirect. The 307 and 308 status codes are relevant only when moving form endpoints or APIs, where the HTTP method (POST, GET, etc.) should be preserved.
Search engines treat 301 and 302 redirects differently. A 301 (permanent) redirect is a strong signal that the target URL should become the canonical (preferred) version. Search results will gradually show the new URL over time. A 302 (temporary) redirect, on the other hand, is a weak signal, and the original URL may remain in search results for an extended period.
Neither type of redirect causes ranking value to be lost, but a long-lasting 302 may eventually be treated as permanent, making the decision uncertain. If the move is permanent, it's better to explicitly use a 301 redirect.
The blog under examination performs several redirects using WordPress on its own. All redirects result in the same content but differ in spelling variations like http vs. https, www vs. none, trailing slashes, and permalink formats. These canonical decisions are permanent (301 redirects). The only instance of a 302 redirect occurs when moving from the admin panel to the login page, which is genuinely temporary. After logging in, users are redirected back to the admin screen.
WordPress generates three specific types of 301 redirects: redirect_canonical(), wp_old_slug_redirect(), and redirect_guess_404_permalink(). The first function ensures that URLs differ from WordPress's canonical version are permanently redirected. The second function handles changes to a published post's slug, while the third rescues URLs that would result in a 404 error by looking for posts with similar slugs.
It's crucial to understand that WordPress defaults to 302 redirects, which may lead to confusion. If a permanent move is intended (such as changing from HTTP to HTTPS or switching domains), explicitly use a 301 redirect and call the exit function to prevent unintended redirections. If a 301 is used incorrectly, browsers may continue to cache the older URL, causing issues when the target changes.
To avoid this, test with a 302 redirect first, then switch to a 301 once the target is confirmed. Always verify the redirect with curl, not just a browser.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.