301 or 302: which redirect to use, and how to check what yours really is

Short answer: a 301 says “moved for good”, a 302 says “it is elsewhere for now”. If the old address is not coming back, it is a 301. Choosing is not the hard part: confirming what the server actually returns is, because some tools set a 302 without telling you, and a mistake like that can go unnoticed for months.

The basics (when you changed a page or a domain, and the three ways to do it) are in 301 redirects. This article covers the choice between the codes and how to verify them.

The four codes

Code What it says When to use it
301 Moved for good. A page changed address, you changed domain, you moved to HTTPS, you chose with or without www.
302 It is elsewhere for now. A promotion that ends, a maintenance page, a test page.
308 Moved for good, and the request is repeated as it was (a form submission remains a form submission). Addresses that receive forms or calls from other programs and have moved for good.
307 Temporary, with the same care as the 308. Rarely by hand. It turns up where the request method has to be preserved.

What this changes for Google

With a 301, search engines start showing the new address and treat the old one as replaced. With a 302 they tend to keep the old one in search, because they were told the move is provisional. A 302 left in place for a long time may end up being treated as permanent, but it is not something to count on.

How to check what your redirect is

1 Open the old address in a private window. It has to end up on the new one. The browser remembers 301s for a long time, and a private window stops an old mistake from fooling you again.
2 Ask for the headers only. In a terminal, curl -I followed by the old address shows the first line of the response (the number, 301 or 302) and a location line with the destination.
3 Follow the whole chain. curl -IL follows the hops and shows each response. From old to new there should be one. Every extra hop slows the visitor down and is a place where the chain can break.
4 If you prefer the browser, open the developer tools, the Network tab, and keep the log preserved before reloading the page: the 301 or the 302 shows on the first line.
5 Fix it at the right level. cPanel’s Redirects tool lets you choose “permanent” (301) or “temporary” (302). In a plugin, the type is usually in each rule’s options. In a file, the code is in the rule itself: .htaccess for PHP projects.
Test with a 302 and switch to 301 at the end. The browser remembers a 301 for a long time: if the destination is wrong, it keeps going to the wrong place even after you fix it. The costliest mistakes are sending every old page to the home page, building chains (A to B, B to C), and a rule that sends an address to itself, which gives the “redirected too many times” error.
When you change the site’s preferred address (with or without www, or HTTP to HTTPS), the rule is always a 301: see www or no www and HTTP or HTTPS.

The redirect is not doing what you expected? Tell us the old address, the new one and what the terminal shows.

Open a support ticket

SEE ALSO

301 redirects when you change a page or a domain

.htaccess for PHP projects: friendly URLs and redirects

How to redirect HTTP to HTTPS with .htaccess

Domain registration

RECOMMENDED PRODUCT

Web hosting with cPanel

Domain and SSL included, daily backups and the panel you already know. from $6.59/mo (3-year plan, with coupon)

See plans
  • 0 Users Found This Useful
Was this answer helpful?