Zubair Akhtar logo — Muhammad Zubair Akhtar, Software Engineer

Blog

301 Redirect vs 302: When to Use Each

A 301 redirect is for a URL that moved for good. See 301 vs 302, how 307 and 308 differ, and when a 410 Gone is the better response than a redirect.

Muhammad Zubair Akhtar

A 301 redirect is the response you send when a URL has moved and the move is meant to last. Browsers follow it. Google can treat the target as the URL that should appear in results. A 302 is the temporary form of the same idea: send people to another address, and leave the original as the URL that can stay indexed. This page is the 301 vs 302 redirect choice, including 307 and 308, and the case where a 410 Gone is the better response because there is no page that should inherit the old address.

I am Muhammad Zubair Akhtar, a senior software engineer in Lahore, Pakistan. I ship Laravel, WordPress, and Next.js. A wrong status is one of the first things I check when the wrong URL is the one in Google, or when a URL that should be gone is still there. The wider pass is the technical SEO checklist. If you want that pass on a live property, it sits under technical SEO services.

On 13 November 2026 I read Google's Redirects and Google Search page, updated 14 April 2026, How HTTP status codes affect Google's crawlers, updated 4 February 2026, the site move guide, the A/B testing page, and the May 2023 office hours note on long-standing temporary redirects. I also read the Next.js redirects reference, the Laravel 12.x routing page, and the WordPress docs for wp_safe_redirect and wp_old_slug_redirect. I have not run these snippets for this article.

Decision flow for a 301 redirect: a permanent move uses 301 or 308, a temporary move uses 302 or 307, and a removed URL with no replacement uses 410

Figure 1. Three answers. A real replacement that will stay is 301 or 308. A short stand-in is 302 or 307. No replacement is 410, not the homepage.

What a 301 redirect changes

A redirect is an instruction to request a different URL. The status code says whether that instruction is permanent, and whether the next request should keep the original method. People usually only see the page they land on. Google uses the status when it decides which URL can be the result.

Permanent and temporary

Google's redirects guide draws the line this way. A permanent redirect can be the signal that the target is the canonical URL, so the target is what shows in results. A temporary redirect is not used as that signal. The source can stay the result. The target might still be indexed if other canonical signals point at it.

On the crawling status-code page, the same split is a strong signal versus a weak one. A 301 is a strong signal that the target should be processed. A 302 is a weak signal that the target should be processed. That page also says other Google products may handle a 302 differently. The notes below are about Google Search.

Use a permanent redirect when you are sure you will not put the old URL back. Use a temporary redirect when the original URL is still the one you want kept, and the other address is only where people go for now.

307, 308, and the request method

301 and 302 are the codes most server configs emit. 308 and 307 are the pair that keep the HTTP method.

Many clients turn a POST into a GET when they follow a 301 or a 302. Next.js documents that as the reason it does not use those two codes in redirects(). A 307 is a temporary redirect that keeps the method. A 308 is a permanent redirect that keeps the method. A form POST that should still be a POST on the next URL wants 307 or 308, not 302 or 301.

Google's crawling page treats them as the same pair for Search. 307 is equivalent to 302. 308 is equivalent to 301. The page also says the codes are still semantically different, and that you should send the one that matches the move so other clients can use it. For Google, a Next.js permanent: true redirect is a permanent redirect even though the status on the wire is 308, not 301.

Signals, without a percentage

I am not quoting a share of "link equity" passed or lost. The pages I read do not publish one. What they do publish is which URL is the candidate.

A permanent redirect is how a renamed URL, a host change, or a migration tells Google the new address is the one to keep. A temporary redirect is how you avoid that transfer while people are briefly somewhere else. Internal links, the sitemap, and the canonical on the destination still matter. A redirect does not replace them. Google's site-move guide says to point canonicals at the new URLs once the redirects are live, and to list those URLs in the sitemap.

The body of the redirecting response is ignored. The crawling page says any content received from the redirecting URL is ignored, and the final target is what gets processed. A schema block on the old URL is not a substitute for schema on the page that answers 200. That markup belongs on the destination, which is the subject of the schema markup guide.

Caching

A permanent redirect is a poor place to experiment. Next.js documents permanent: true as a 308 that instructs clients and search engines to cache the redirect forever, and permanent: false as a 307 that is temporary and is not cached. A 301 can also be stored. Changing your mind later means some browsers keep sending people to the old target until that stored response expires.

I am not quoting a browser's max-age. The practical rule is enough: use 301 or 308 when the move will stay, and 302 or 307 when you may remove it.

301 vs 302 vs 307 vs 308 vs 410

CodeMeaningGoogle SearchMethodUse it when
301Moved permanentlyStrong signal. The target can be the resultClients often repeat the next request as GETThe URL has moved for good
302Found. TemporaryWeak signal. The source can stay the result. A long-standing 302 can be treated as permanentClients often repeat the next request as GETA short test, campaign, or stand-in
307Temporary redirectTreated like a 302Method and body stayA temporary redirect that must keep POST
308Permanent redirectTreated like a 301Method and body stayA permanent move, including Next.js permanent: true
410GoneNot a redirect. An indexed URL that returns 410 is droppedNo followRemoved or spam, and no real replacement

Read the row before you copy a snippet. A 301 to a page that is only up for a week is the wrong row. A 302 that you leave in place for a migration is also the wrong row. A 410 is the row where there is no destination.

When to use a 301 redirect

Send a 301, or a 308 where the framework uses that for a permanent move, when all of these are true:

  • The old URL should stop being the address people and Google keep.
  • There is one real page that replaces it. The closest matching page, not a generic landing page.
  • You do not plan to put the old URL back.

The usual cases:

  • A renamed path, such as /services/old-name to /services/seo.
  • HTTP to HTTPS, and www to the apex, or the apex to www. Pick one host and one scheme. Send the other forms there in a single hop.
  • A domain or directory migration, where each old URL has a mapped new URL.
  • Two URLs that are the same document. Keep one, and permanently redirect the other.

Google's redirects guide recommends a permanent server-side redirect when you need to change the URL that shows in results. The site-move guide says the same for a move: server-side 301 or 308, each old URL to its final URL, kept for at least a year so signals can move. HTTP to HTTPS, and www versus the apex, are permanent redirects. They are not a Change of Address filing. The cutover steps for a WordPress move are in the WordPress migration guide.

Update your own links to the final URL. A redirect is the safety net for bookmarks and outside links. It should not be the way your templates reach a page you still control.

When to use a 302

Send a 302, or a 307 when the method has to stay, when the original URL is still the one that should be canonical and the other URL is temporary.

A short stand-in

Google's redirects guide uses a clear example: a service that is temporarily unavailable can send people to a page that explains the situation, with a temporary redirect, so the original URL stays eligible for results.

That is a stand-in for one URL, for a short time. A whole site that is down is a different status. A 503 says the server is unavailable. The crawling page treats 503 as a server error: crawling slows, and a URL that keeps returning a server error can eventually be dropped. Keep a maintenance window short. Do not permanently redirect the site to a holding page. A 301 would nominate the holding page as the new address.

A/B tests and campaigns

Google's testing guide says to use a 302, not a 301, when a test redirects people from the original URL to a variation. The 302 says the redirect lasts only as long as the experiment, and that the original URL should stay indexed rather than be replaced by the test page. The same guide says to remove the test, including alternate URLs, as soon as you have a result. An experiment left running for an unnecessarily long time can be read as an attempt to deceive, especially if a large share of users see a different version.

A campaign URL that should rank on its own, such as a landing page you will delete next month, can be a 302 back to the durable page when the campaign ends. While the campaign is live and should be indexed, it is a 200, not a redirect.

A long-standing 302

In the May 2023 Search Central office hours, John Mueller said Google Search recognizes long-standing temporary redirects as permanent ones. He also said it is still worth sending the status that matches the intent. I am not treating that note as a deadline, and I am not quoting a number of days. The practical reading is: a 302 you leave up because the move was actually permanent can end up doing a 301's job, on Google's timetable rather than yours. Change a permanent move to 301 or 308. End an A/B test instead of hoping the source URL stays canonical forever.

Chains, loops, and the homepage

One redirect hop from the old URL to the final URL, versus a chain that should be flattened and a loop that never resolves

Figure 2. Point each old URL at the final URL. A chain still resolves until it gets too long. A loop does not resolve.

One hop

A chain is /old to /interim to /new. A loop is /old to /new and /new back to /old. The crawling page says Google's crawlers follow up to 10 redirect hops by default. Past that, the redirect fails. The site-move guide asks you not to rely on the limit: redirect to the final destination, and if you must chain, keep it low, ideally no more than 3 and fewer than 5. Chains add latency, and not every client will follow a long one.

The usual way a chain appears is a second system adding a hop the first one already did. The edge redirects HTTP to HTTPS, then the app redirects the host, then a plugin redirects the path. Collapse that to one response that sets scheme, host, and path together.

The sitemap should list the final URL that returns 200. Leave redirects and 410s out of it. That check is already on the technical SEO checklist.

Do not send everything to the homepage

A catch-all that sends every unknown path to / feels tidy. Google's site-move guide says not to redirect many old URLs to one irrelevant destination, such as the home page. That pattern can be treated as a soft 404. People who asked for a product or a post land on a page that is not that thing. Google may not treat the homepage as the new canonical for those URLs.

A soft 404 is also a 200 whose body is an error. The status and the page have to agree. A missing URL with a real replacement gets one redirect to that replacement. A missing URL with no replacement gets 404 or 410, including when you still show a helpful HTML page with that status. It does not get a 301 to /.

How to send the status

Server-side redirects are the ones Google's guide ranks highest. Meta refresh and JavaScript redirects are fallbacks for a host where you cannot set the status. I use the server. The snippets below are the shapes I copy. The hosts are placeholders.

Nginx

For the scheme and host, one return on the HTTP server does the whole hop. $request_uri keeps the path and the query string. Put this on port 80 only. The same line inside the HTTPS server, aimed at itself, is a loop.

server {
    listen 80;
    listen [::]:80;
    server_name example.com;
    return 301 https://example.com$request_uri;
}

For one retired path, an exact location beats a prefix. return 301 /new drops the query string. $is_args$args keeps it.

location = /old {
    return 301 /new$is_args$args;
}

A 302 is the same line with 302. A removed path with no replacement is return 410 in that exact location. The rest of a production Nginx setup, including the proxy in front of PHP or Node, is the Nginx setup guide. .htaccess rules do nothing on Nginx.

Apache

Redirect is prefix matching. This sends /old to /new, and it also sends /old/child to /new/child and /oldest to /newest, because those paths begin with /old.

Redirect 301 /old /new

For one URL, match the path exactly:

RedirectMatch 301 ^/old/?$ /new

A temporary redirect is Redirect 302 /sale /pricing, with the same prefix warning. A gone URL is RedirectMatch 410 ^/removed/?$. If the target has no query string, Apache appends the original query string. A target that already contains ? replaces it.

After you edit .htaccess, request the old URL and read the status before you reload a browser that may have stored an earlier 301.

Redirects in WordPress

WordPress redirects are a small map, not a plugin pile, until the map outgrows a few lines. Two core behaviors are worth separating before you add a rule.

wp_safe_redirect() defaults to 302. Pass 301 when the move is permanent, and follow it with exit. The WordPress docs say the function does not exit on its own. wp_safe_redirect() also checks the host. wp_redirect() does not, so a location taken from the request can become an open redirect. I use the safe variant unless the target is an external host I have written down.

add_action('template_redirect', function (): void {
    $path = trim((string) parse_url($_SERVER['REQUEST_URI'] ?? '', PHP_URL_PATH), '/');
    if ($path !== 'old-offer') {
        return;
    }

    wp_safe_redirect(home_url('/pricing/'), 301);
    exit;
});

Leave off the 301 and this is a 302. Put the hook in a small plugin if a theme update would wipe functions.php.

Renaming a post is a different path. wp_old_slug_redirect() runs on a 404, looks up a previous slug, and sends wp_redirect() with 301. The function returns immediately for hierarchical post types, so it does not cover Pages. It also does not cover a deleted post, a permalink-structure change, or a new domain. Those need an explicit map. A domain move is the WordPress migration guide.

A long list belongs somewhere that survives a theme switch: a small plugin, or Apache rules if the host is Apache. A redirect manager in wp-admin is fine when someone else has to edit the map. I have not installed one for this article. The rules are the same either way. One old path, one final URL, 301 for a permanent move, 302 for a temporary one, and no catch-all to the homepage. That work sits under WordPress development when the map is part of a build rather than a one-line fix.

Next.js

redirects() in the Next.js config is the list you know at build time. permanent: true is a 308. permanent: false is a 307. Query values on the request are passed through to the destination.

async redirects() {
  return [
    {
      source: '/old',
      destination: '/new',
      permanent: true,
    },
    {
      source: '/sale',
      destination: '/pricing',
      permanent: false,
    },
  ];
}

Google treats that 308 like a 301 and that 307 like a 302. I use permanent: true for a move that will stay. I do not force a 301 just so the number matches an older checklist.

If an older client needs a literal 301, the Next.js reference allows statusCode instead of permanent. Do not set both on the same object.

{
  source: '/old',
  destination: '/new',
  statusCode: 301,
}

permanentRedirect() in a Server Component is also a 308 outside a Server Action. A Server Action uses a client navigation when JavaScript is available, and a 303 for a form post without it. That is a different tool from a URL you retired in the config. For a path you know in advance, redirects() is the one I want, because it runs before the page renders.

A catch-all redirect to / is still a soft-404 risk in Next.js. Unknown URLs that were never pages, including spam, should not be sent to the homepage. On this site those URLs answer 410. The write-up of that choice is how I removed hacked spam URLs from Google.

Laravel

Laravel 12's routing docs give two shortcuts. Route::redirect() returns 302 unless you pass a status. Route::permanentRedirect() returns 301.

Route::permanentRedirect('/old', '/new');

Route::redirect('/sale', '/pricing');

Route::redirect('/old', '/new', 301) is the same permanent result as permanentRedirect. If the route uses parameters, destination and status are reserved names and cannot be parameter names.

These lines are the path-to-path case. They are the right tool when the map is short and lives in routes/web.php. A long migration map is still data: one old path, one new path, one status. The edge, Nginx or the host in front of PHP, is a better place for the HTTP-to-HTTPS hop so the application is not a second redirect. That split is the Nginx setup guide.

When a 410 is the better answer

A 410 is not a redirect. There is no Location header and no replacement URL. Use it when the page was removed on purpose and nothing should inherit it: a retired campaign, a deleted URL with no successor, or an address you never published.

Google's crawling page groups 410 with the other 4xx codes, except 429. The content is not used. An indexed URL that starts returning 4xx is removed from the index. I am not claiming 410 is dropped on a faster timer than 404. The current page treats those client errors the same way. The reason to pick 410 is the meaning: this URL is gone, and you are not nominating another page as its replacement.

Spam and hacked URLs are this case. A 301 from those paths to the homepage is the soft-404 pattern above. The cleanup I use, and why the URL has to stay crawlable so Google can see the 410, is in how I removed hacked spam URLs from Google. A Disallow in robots.txt hides that status. The robots.txt guide is the distinction between a path you do not want fetched and a path you want removed.

The minimal server forms are return 410; in an exact Nginx location, and RedirectMatch 410 ^/removed/?$ on Apache. I am not pasting an allowlist here.

FAQ

What is a 301 redirect?

A 301 redirect is a permanent server response that sends the request to a new URL. Google can use it as a strong signal that the target should be the URL in results. Use it when the old address is not coming back and a real page replaces it. Next.js redirects() with permanent: true sends 308 for that same permanent case, and Google treats 308 like 301.

When should I use a 302 instead of a 301?

Use a 302 when the original URL should stay the canonical address and the other URL is temporary: a short stand-in, a campaign, or an A/B test. Google's testing guide asks for a 302, not a 301, for that test. A 307 is the temporary code that also keeps the HTTP method.

Does a long-standing 302 become a 301?

Google can treat it as one. In the May 2023 office hours, John Mueller said Google Search recognizes long-standing temporary redirects as permanent ones, and that it is still better to send the status you mean. There is no number of days on that page. If the move is permanent, send 301 or 308. If the 302 is a test, end the test.

Should deleted or spam URLs redirect to the homepage?

No. A pile of unrelated URLs redirected to the homepage can be treated as a soft 404. Send a deleted URL to the one page that replaced it, or answer 404 or 410 when nothing replaced it. Spam and hacked URLs are a 410. The steps for that are in how I removed hacked spam URLs from Google.

Do I have to keep a 301 forever?

Google's site-move guide says to keep migration redirects for at least a year, and longer from the user's side of old bookmarks. I keep a permanent move in place while anything still requests the old URL. I remove a 302 when the temporary reason is over, so it does not sit long enough to be read as permanent.

If you want the map checked

I read a redirect as one old URL, one final URL, and a status that matches whether the move will stay. Chains get flattened. Removed URLs with no successor answer 410. The homepage is not the destination for the rest of the site.

That pass is part of technical SEO services. Send the old-to-new list, or the Search Console reports for redirect errors and soft 404s. I start by requesting one old URL and the page it should become.

Discuss this with Muhammad

Message Muhammad Zubair Akhtar on WhatsApp or email [email protected].