What Is a 301 Redirect? How to Set It Up and Its SEO Impact
What is a 301 redirect and when should you use it? The 302 and 308 difference, .htaccess, Nginx and PHP examples, redirect maps and tests that protect traffic.
A 301 redirect is an HTTP status code that tells browsers and search engines that a URL has moved permanently to a new address. The server answers a request for the old address with a 301 Moved Permanently response and a Location header pointing to the new one. Google uses this redirect as a strong signal that the new address should be the canonical URL shown in search results.[1]
In this post I explain how a permanent redirect works, how it differs from 302, 307 and 308, how to set it up on Apache, Nginx, PHP and static hosting services, and how to test it so that traffic is protected. Redirects are one of the core tools on the crawling and indexing side of technical SEO. I describe how I run these audits in my own projects on the SEO services page.
How does a 301 redirect work?
A 301 redirect works by having the server send the new address instead of content for the old URL. A browser or Googlebot requests the old URL. Instead of the page content, the server returns a 301 status code and a Location header. The client makes a second request to the address in that header and gets the page from there.
In a terminal, the raw response of a redirect looks like this:
HTTP/1.1 301 Moved Permanently
Location: https://www.example.com/new-page/
Cache-Control: max-age=3600
According to RFC 9110, the document that defines HTTP semantics, a 301 means the target resource has been assigned a new permanent address and future references should use it.[4] The same document says a 301 response is cacheable by default.[4] This detail matters in practice: even after a wrong 301 rule is fixed, a visitor’s browser may remember the old redirect for a while.
On Google’s side, a permanent redirect is a canonicalization signal. Canonicalization is the process in which Google picks the single address it will show in search results among several URLs with the same content. According to Google’s documentation, Googlebot follows the permanent redirect and the indexing pipeline takes it as a signal that the target page should be canonical.[1] I cover how it relates to the canonical tag in the post on the canonical tag.
What is the difference between a 301 and a 302 redirect?
A 301 is a permanent redirect, a 302 is a temporary one, and Google interprets them differently. With a permanent redirect, Google tends to show the new address in search results. With a temporary redirect, it keeps the old address in results, because it assumes the page will come back.[1]
301 / 308 (permanent)
- The new URL becomes canonical
- Search results show the new address
- Strong canonical signal for Google
- Site moves, URL changes, HTTPS migration
302 / 307 (temporary)
- The old URL stays canonical
- Search results usually keep the old address
- Weak canonical signal for Google
- Maintenance, temporarily out-of-stock product, short campaign
Seeing all redirect types in one table makes the decision easier:
| Method | Google’s interpretation | When to use it |
|---|---|---|
301 Moved Permanently | Permanent | URL change, site move, domain consolidation |
308 Permanent Redirect | Permanent | Permanent move when the request method must be kept |
302 Found | Temporary | Short maintenance or a test |
307 Temporary Redirect | Temporary | Temporary move when the request method must be kept |
| Meta refresh (0 seconds) | Permanent | When you have no server access |
| Meta refresh (delayed) | Temporary | Not recommended |
| JavaScript redirect | Uncertain | Only when there is no other option |
The interpretations in the table are based on Google’s redirect documentation.[1] The difference between 301 and 308 lies in the request method. RFC 9110 states that, for historical reasons, a client may change a POST request to GET after a 301, and that a 308 can be used if this is not wanted.[4] On normal web pages this difference has no effect on SEO. For addresses that submit forms or send requests to an API, however, a 308 redirect is the safer choice.
When should you use a 301 redirect?
A 301 redirect is used when content has moved permanently to a new address and it is certain the old address will not be used again. The rule carries the links, bookmarks and search signals the old URL has collected over to the new page.
Typical use cases are:
- URL structure change: Moving from
/blog/2024/post-nameto a new pattern such as/articles/post-name/. - Domain change: Moving every URL of the old domain to the new domain when the brand name or extension changes.
- HTTP to HTTPS migration: Redirecting every request to the insecure version to the secure version.
- Consolidating versions of the same address: Merging the
wwwand non-wwwversions, trailing slash differences and uppercase-lowercase differences into one address. - Content consolidation: Merging two weak posts that answer the same question into one strong post and pointing the old one to the new post.
- Removed product or service: Pointing the old page to a genuinely similar product or category, if one exists.
Google recommends that if your home page can be reached at several addresses, you pick one as the preferred address and permanently redirect the others.[1] Content consolidation is one of the cleanest ways to fix keyword cannibalization. I also cover how I make that decision in the post on SEO-friendly content.
When should you use another method instead of a 301?
Not every moved or removed page needs a 301. If there is no similar page that can replace the content, returning a 404 or 410 is a more honest answer. If the page will stay but should not appear in search results, noindex is the right tool. If both addresses of the same content will stay accessible, a canonical tag is enough.
How do you set up a 301 redirect?
A 301 redirect is defined in the server configuration, in application code or in the hosting service’s redirect file. Google recommends a permanent server-side redirect whenever possible, because this method has the highest chance of being interpreted correctly.[1]
Short answer
How do you set up a 301 redirect?
To set up a 301 redirect, you first prepare a map that pairs old and new URLs. Then you write the rule that fits your server, test it with curl and take it live. In the final step you update internal links and the sitemap with the new addresses and monitor the reports in Search Console.
- Prepare a redirect map that pairs old and new URLs.
- Identify the server type: Apache, Nginx, application code or static hosting.
- Write a single-hop 301 rule for every old URL.
- Verify the rules with curl in a staging environment first.
- Go live and update internal links and the sitemap with the new URLs.
- Monitor the crawling and indexing reports in Search Console.
With Apache and .htaccess
On an Apache server, the simplest method is the Redirect directive of the mod_alias module. For more flexible patterns, mod_rewrite is used. LiteSpeed servers also read most .htaccess rules the same way.
The first line below moves a single page. The second block moves the /blog/ folder to the /articles/ folder with a pattern. The third block sends the HTTP and non-www versions to the https://www version in a single hop.
Redirect 301 /old-page/ https://www.example.com/new-page/
RewriteEngine On
RewriteRule ^blog/(.*)$ /articles/$1 [R=301,L]
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
The last block matters. If you write two separate rules, one from HTTP to HTTPS and one from non-www to www, the address http://example.com creates a two-hop chain. Combining the conditions in one rule reduces the chain to a single hop.
With Nginx
In Nginx, a permanent redirect is written with return 301. This method is faster than the rewrite directive, because it does not process a regular expression.
location = /old-page/ {
return 301 https://www.example.com/new-page/;
}
server {
listen 80;
server_name example.com www.example.com;
return 301 https://www.example.com$request_uri;
}
With PHP and application code
If you have no access to the server configuration, you set up the redirect in application code. In PHP, headers must be sent before any output is written to the page.[1]
<?php
header('Location: https://www.example.com/new-page/', true, 301);
exit;
If you use WordPress, a plugin such as Redirection or the redirect module of an SEO plugin does the same job. In Shopify, redirects are defined in the URL redirects section of the admin panel; I cover the platform’s limits on this in the post on Shopify SEO.
With static sites and Cloudflare Pages
On serverless sites, such as the static output of Astro, Hugo or Next.js, redirects are defined in the hosting service’s redirect file. On Cloudflare Pages this file is called _redirects, and each line consists of a source path, a destination path and a status code.[5]
/old-post/ /articles/new-post/ 301
/blog/* /articles/:splat 301
According to Cloudflare’s documentation, a _redirects file can hold up to 2,000 static and 100 dynamic redirects; Bulk Redirects is recommended for larger lists.[5] If no status code is written, the default is 302, so for a permanent move you need to write 301 explicitly.[5] I explain how I build the SEO foundation of a static site in the post on Astro SEO.
How do you prepare a redirect map?
A redirect map is a table that pairs every old URL with its matching new URL, and it is the foundation of a correct 301 setup. Writing the code is the easy part. Deciding where each old address should go is what determines whether traffic is protected.
- Get the full list of old URLs
Combine the current sitemap, the output of a crawler such as Screaming Frog and the list of indexed pages in Search Console. Add URLs that were visited recently according to the server logs.
- Flag the valuable URLs
In a separate column, mark the pages that get clicks in Search Console and the URLs that have external links. Choose the best target for these pages one by one.
- Map one to one
For every old URL, write the new URL closest in content. Mark pages with no match as 404 or 410, and do not point them to the home page.
- Turn patterns into rules
Write pattern rules for groups of URLs that follow the same structure, and put exceptions first as single-line rules. Rule order matters; the first matching rule is applied.
- Do not forget images and files
If the URLs of embedded images, PDFs and videos change, add them to the map too. Google recommends including this content in the list in its site move guide.
Google’s site move guide recommends that when you build the list of old URLs, you include addresses visited recently according to the server logs as well as embedded images and videos.[2] For a domain change, the guide also asks you to verify all versions of the old and new site in Search Console.[2]
Why do redirect chains and loops cause problems?
A redirect chain is when a URL reaches its final destination through more than one redirect hop, and every hop adds crawl time and page load time. For example, if http://example.com/a first goes to the HTTPS version, then to the www version, then to the new path, it forms a three-hop chain.
According to Google’s crawling documentation, Google’s crawlers follow up to 10 redirect hops by default.[3] This limit may look generous, but it can be exceeded by moves that pile up over the years. Even when the limit is not reached, every extra hop is another network request for the user. That is why I point every old URL directly at the final destination when I write rules.
A redirect loop is when A goes to B and B goes back to A. In that case the browser shows a “too many redirects” error and the page never opens. Loops usually come from conflicting rules written in two different layers: for example, a trailing slash rule defined both in the CDN and in the application code.
How do you test a 301 redirect?
A permanent redirect is tested most reliably with curl in a terminal, because browsers cache 301 responses and may show even a fixed rule in its old form. The curl -I command fetches only the headers, and the -L flag follows the chain to the end.
The first command shows the status code and target of a single hop. The second command follows the chain to the end and prints the number of hops.
curl -sI https://example.com/old-page/ | grep -iE "^(HTTP|location)"
curl -sIL -o /dev/null -w "%{num_redirects} hops, final code %{http_code}: %{url_effective}\n" http://example.com/old-page/
In the output of the second command, the hop count should be 1 and the final code 200. For many URLs, you run the same check in a crawler’s list mode. Search Console’s URL Inspection tool also shows how Google sees the page; I explain how I read the reports in the post on how to use Google Search Console.
What should you do after a 301 redirect?
After the redirects go live, you need to update internal links, the sitemap and canonical tags with the new addresses. A redirect is a bridge for old links coming from outside. Inside your own site, however, every link should point directly at the final address; otherwise every internal click adds an unnecessary hop.
Put only new URLs that return 200 in the sitemap. A redirected address left in the sitemap sends Google a contradictory signal. I explain how to build a proper sitemap in the post on the XML sitemap. If the domain has changed, you also need to use the Change of Address tool in Search Console.[2]
How long the redirects stay in place is also a decision. For site moves, Google recommends keeping redirects for as long as possible, generally at least one year. This time is needed for Google to recrawl the old URLs and reassign links on other sites to the new addresses.[2] I do not remove permanent redirects, because a link in an old forum post or email can still be clicked years later.
Finally, watch the traffic. According to Google’s site move guide, a move happens on a per-URL basis and Googlebot has to visit every URL on the old and new site at least once.[2] That is why ranking fluctuations in the first weeks are normal. Checking 404 errors and the “page with redirect” list in Search Console every week catches missed mappings early.
Summary
A 301 redirect is an HTTP status code that says a page has moved permanently to a new address and lets Google carry signals over to that address. For temporary situations, use a 302 or 307; for permanent moves where the request method must be kept, use a 308. What decides the outcome is not the code itself but a redirect map that connects every old URL to the closest matching new page in a single hop.
As a next step, test a few of the most-clicked old URLs on your site with curl -sIL. If the hop count is more than one or the final code is not 200, start by fixing the chain and the target.
Key terms
- 301 redirect
- A 301 redirect is an HTTP status code that says a URL has moved permanently to a new address. The server gives the new address in the Location header. Google treats this code as a strong signal that the new address should be shown as the canonical URL.
- 302 redirect
- A 302 redirect is an HTTP status code that says a page is temporarily served from another address. The user goes to the new address, but Google usually keeps the old address in search results. It is used for temporary situations such as maintenance, an out-of-stock product or a short campaign.
- 308 redirect
- A 308 redirect is an HTTP status code that signals a permanent move like a 301 but does not allow the client to change the request method. A POST request also goes to the new address as a POST. Google treats a 308 the same way as a 301, as a permanent redirect.
- Meta refresh
- Meta refresh is a tag placed in the HTML head that sends the browser to another address after a set time. Google interprets a 0-second meta refresh as a permanent redirect and a delayed one as a temporary redirect. It is the fallback when a server-side redirect is not possible.
- Redirect map
- A redirect map is a table that pairs every old URL with its matching new URL before a site move or URL structure change. It is built from crawl data, sitemaps and Search Console lists. It is the foundation for writing redirect rules that are correct and complete.
Frequently asked questions
What is a 301 redirect?
A 301 redirect is an HTTP status code that says a URL has moved permanently to a new address. The server answers a request for the old address with a 301 code and a Location header pointing to the new one. Google uses this redirect as a strong signal that the new address should be the canonical URL.
What is the difference between a 301 and a 302 redirect?
A 301 is a permanent redirect and a 302 is a temporary one. With a 301, Google tends to show the new address in search results; with a 302, it usually keeps the old address. Use a 301 if the move is permanent and a 302 for temporary situations such as a few days of maintenance or a campaign.
Does a 301 redirect lose SEO value?
Google treats a permanent server-side redirect as a strong signal that the target should be the canonical URL and moves signals to the new address. Value is usually lost through poor setup: redirects to irrelevant pages, long chains and loops. Pointing each old page to the closest matching new page reduces this risk.
How long should a 301 redirect stay in place?
For site moves, Google recommends keeping redirects for as long as possible, generally at least one year. This time lets Google recrawl the old URLs and reassign links on other sites to the new addresses. Since old links can be clicked for years, it is safer for users not to remove the redirect at all.
Should a deleted page be redirected to the home page?
No, in most cases it should not. Google notes that redirecting many old URLs to one irrelevant destination such as the home page can confuse users and may be treated as a soft 404. If there is no closely matching new page, returning a 404 or 410 is the better choice.
Sources
The full topic: Technical SEO guide ↗