So you need to redirect one page on your website to another, or maybe even your entire website to another domain, but you’re not quite sure whether you should use a 301 or 302 redirect?
I’ve been there myself—and the information I could find on the Internet wasn’t very helpful. I guess that’s why I decided to write this guide for anyone else who’s wondering exactly which type of HTTP redirect to use.
Why This Is Important
For users, there’s little difference, if any, between a 301 and a 302 redirect.
They type a URL into their browser’s address bar and then, they are redirected to another URL. As long as they got the information they wanted from that page, they are happy.
However, it makes all the difference in the world to search engine crawlers:
A 301 redirect is a permanent redirect. It means that the website, page, or file in question will never be accessible at the original URL again. In contrast, a 302 redirect is a temporary redirect, meaning that it will eventually be undone.
In other words, the type of HTTP redirect you choose has important implications for the backlink equity and page rank of your website and web pages.
HTTP Redirects, Explained
Every time you type in the URL of a website (or a particular page you want to visit), a chain of events takes place between your browser and a handful of web servers.
First, your browser performs a DNS lookup to find the IP address of the web server that’s hosting the website. Then, it initiates a TCP connection to that server. Finally, it sends an HTTP GET request to it.
Sometimes, the server won’t serve the files to the browser. Instead, it will respond with a status code beginning with the number 3, telling the browser that the page and/or files in question have been moved, and a
Location HTTP header that contains the URL to redirect to.
For this to happen, the webmaster of the website in question must have configured an HTTP redirect in the main configuration file of the server (in a file called
httpd.conf) or at the directory level of the domain or a specific folder on it (in a file called
Categories and Types of HTTP Redirects
There are seven types of HTTP redirects, and each type falls into one of three categories: permanent redirects, temporary redirects, and special redirects.
Permanent redirects are redirects that are meant to last forever. They mean that the original URL will never be used again and that the website, page, or file in question, whether in its original or an updated version, is available at the new URL.
There are two types of permanent redirects: 301 redirects and 308 redirects. (For the purpose of this post, we will focus only on the HTTP redirects with a status code of
Temporary redirects are redirects that are meant to be undone. For some reason, the requested website, page, or file isn’t available at its original URL. However, instead of throwing an error, the server redirects the browser to a temporary URL where that website, page, or file is available until the original URL is back up and running.
There are three types of temporary redirects: 302 redirects, 303 redirects, and 307 redirects. (For the purpose of this post, we will focus only on the HTTP redirects with a status code of
Special redirects are, as the name implies, special types of redirects that don’t necessarily fall under the definitions of permanent or temporary redirects.
The 300 redirect gives users multiple choices, and the 304 redirect indicates that the original page hasn’t been changed, telling the browser that it can use the locally cached copy despite the fact that it is out of date.
What Is a 301 Redirect?
A 301 redirect is a permanent HTTP redirect. It tells the browser that the requested website, page, or file has been moved to a new URL.
As a general rule of thumb, there are two ways to set a 301 redirect: on a server level, by editing Apache’s
httpd.conf file, or on a directory level, by editing the
.htaccess file in the directory of the website, page, or file in question.
Here’s an example of a 301 redirect rule:
# Permanently redirect old domain to new domain RewriteEngine on RewriteBase / RewriteRule (.*) http://www.destination.com/$1 [R=301,L]
When you set up a 301 redirect, you give search engine crawlers to understand that the change is permanent. This is why these redirects affect your website’s SEO, as the search engines transfer the backlink equity of the original URL to the new URL.
However, this transfer of backlink equity takes time, and it’s recommended that you keep the 301 redirects active for at least a year.
As reported by Search Engine Roundtable, Google’s John Mueller recommends keeping 301 redirects active for a few years. “After a few years,” he said, “the old URLs will no longer be accessed, and you can drop those redirects.”
What Is a 302 Redirect?
A 302 redirect is a temporary HTTP redirect. It tells the browser that the requested website, page, or file is temporarily unavailable at the original URL for unforeseen reasons, and that it can be accessed from a canonical URL instead.
As a general rule of thumb, there are two ways to set a 302 redirect: on a server level, by editing Apache’s httpd.conf file, or on a directory level, by editing the .htaccess file in the directory of the website, page, or file in question.
Here’s an example of a 302 redirection rule:
# Temporarily redirect old domain to new domain RewriteEngine on RewriteBase / RewriteRule (.*) http://www.destination.com/$1 [R=302,L]
Such redirects have no impact on search engine optimization (SEO) because search engine crawlers don’t transfer the backlink equity of the original URL to the temporary URL.
Of course, if the page that the server redirects to temporarily doesn’t meet the searcher’s intent—say, a “We’re having technical problems and we’ll be back soon” page—this can have a negative effect on the search engine ranking of that page unless it’s restored soon.
When to Use a 301 Redirect
Generally, you should set up 301 redirects when you don’t intend to bring the original URLs back.
Some of the most common use cases for 301 redirects are:
- You want visitors and search engine crawlers to only access the HTTPS version of your website.
- You want visitors and search engine crawlers to only access the www or non-www version of your website.
- You changed the URL of a page or file on your website.
- You are merging two or more pages or files on your website.
- You changed your website’s domain name because you’re rebranding or got bought up by a bigger competitor.
- You bought an aged domain name from ODYS, SEO.domains, or SERPpro, and you want to redirect it to your main website.
- You bought an expired domain from GoDaddy Domain Auctions or Sedo, and you want to redirect it to your main website.
When to Use a 302 Redirect
Generally, you should set up 302 redirects when you intend to bring the old URLs back.
Some of the most common use cases for 302 redirects are:
- You’re running an A/B test, and you’re splitting the traffic that a particular web page gets between two or more versions (with different designs, copy, media, etc.).
- You own an online store, and a particular product just ran out of stock. Temporarily, you’re redirecting users to a related product or product category.
- You’re running a Black Friday campaign every year, and you redirect users to a different page on days other than the fourth Tuesday of November.
- You’re redesigning your website, and you’re diverting users to a countdown page until the redesign is complete.
A 301 redirect is permanent; a 302 redirect is temporary. If you don’t intend to bring the old URL of a given website, page, or file back, then set up a 301 redirect. If you do, then use a 302 redirect.