Skip to content

301 redirect

A 301 redirect is a server's answer that an address has moved for good, with the new address attached. Browsers go there by themselves, and Google shows the new address in its results. Use one whenever a page's address changes permanently.

By
WP Ministry
Published

In short

  • A 301 says the move is permanent, and Google then shows the new address in results. A 302 says it is temporary, and the old address stays.
  • WordPress sends some 301s by itself and marks them with the header "X-Redirect-By: WordPress". A redirect written with wp_redirect() is a 302 unless the code asks for a 301.
  • A browser may store a 301 and stop asking the server. Check a changed redirect with a tool that asks every time.

A 301 redirect is the answer a web server gives when an address has moved for good. The answer carries the status code 301, named "Moved Permanently", and a Location line with the new address. The browser requests that address by itself, so the visitor lands on the new page. The HTTP specification says future references ought to use the new address.

Three other codes do a similar job:

CodeSaysA submitted formGoogle shows
301Moved for goodMay be sent on as a plain GETThe new address
308Moved for goodSent on unchangedThe new address
302Moved for nowMay be sent on as a plain GETThe old address
307Moved for nowSent on unchangedThe old address

For a page that people read, use a 301.

Where you meet it

  • WordPress sends its own. Ask for a post without its final slash, or by its ?p=123 form on a site whose permalinks use post names, and WordPress answers 301 to the proper address. It does the same for the old address of a post whose slug changed. These answers carry the header X-Redirect-By: WordPress, which shows the redirect came through WordPress and not from the server's own rules.
  • In code. wp_redirect() sends a 302 unless it is given 301 as its status.
  • A plugin's list, .htaccess or the nginx configuration. These are where you add your own. How to set up redirects in WordPress covers all three.

What goes wrong

A 302 where a 301 was meant. Google treats a temporary redirect as a reason to keep the old address in its results.

Chains and loops. Google's crawler follows up to 10 hops, and Google's advice is to redirect straight to the final address. A loop never arrives: see how to fix ERR_TOO_MANY_REDIRECTS. The redirect map builder points out both before the rules go live.

The browser remembers. The specification lets a browser store a 301 and reuse it without being told to. A 302 is not stored that way. Change or delete a 301 and your own browser may keep following the old one.

Redirects removed too soon. Google states two periods. Its help for the Change of Address tool says at least 180 days, and longer while Google Search still sends visitors to the old addresses. Its site-move guide says as long as possible, generally at least 1 year. How to migrate a website without losing SEO has the rest.

How to look at yours

bash
curl -sI https://example.com/old-page/

Among the lines it prints, the first is the status and Location is where the address leads:

text
HTTP/1.1 301 Moved Permanently
X-Redirect-By: WordPress
Location: https://example.com/new-page/

The redirect checker shows the same for every hop, without a command line.

Common questions

What is the difference between a 301 and a 302 redirect?

A 301 says the page has moved permanently, and a 302 says the move is temporary. Visitors are sent on either way. The difference is in search results: Google shows the new address after a 301 and keeps the old one after a 302.

How long should a 301 redirect stay in place?

At least a year where you can. Google's site-move guide says to keep redirects as long as possible, generally at least 1 year, and its Change of Address help gives 180 days as the least.

Why does my browser still follow a redirect I deleted?

It stored the 301 and is not asking the server again. Check the address with curl or the redirect checker, which make a fresh request each time.

Not sure what is wrong?

Tell us what you see. We reply with the cause and a fixed quote, and the diagnosis is free.