Redirecting a web page can be tricky.
You know that there are at least two ways to do this.
A 301 or a 302 redirect.
But which one do you choose?
Making a mistake could cause your page to drop in search rankings.
This article will make it clear when to use a 301 or a 302.
We call these numbers HTTP status codes.
Did you know there are also some other status codes you can use? 307 and a 308 are both also useful for redirection.
We will help you decide when to use each status code and how.
But before we can do that you need to understand a bit about HTTP request methods.
What are HTTP Request Methods?
When your browser makes an HTTP request to a server it does so using a request method. Here are two examples:
- GET - Read a file from a server
- POST - Send data to a server
When you type a webpage URL into your browser you are making a GET request to the webserver. This is reading the HTML file from the server.
Filling out an online form such as a “contact us” form is a good example of a
POST request. When you hit the submit button your browser takes the data you entered and sends it to the webserver.
The type of method (POST, GET) a request uses helps us decide which redirect status code (301, 302, 307 or 308) to use.
There is one more thing to understand about redirects and that is link juice.
Link juice is an industry term to describe the number of inbound links to a webpage. For example, the more high quality links that a page has the more “juice” it has.
When redirecting a page it is important to remember:
Some status codes will pass link juice and some won’t.
The general rule is that if you want to redirect permanently then you want to pass the link juice.
If the redirection is only temporary then choose a status code that does not pass the link juice.
Next, let’s look at the status codes.
What are HTTP status codes?
Every time your browser requests to view a webpage the server responds with a status code.
For example, when a request is successful the server returns a 200 status code. If there is a server error then the server returns a 500 status code.
A 300 HTTP Status code deals with redirection.
Redirection is about sending one page to another.
There are a few status codes to choose from when redirecting.
Choosing the wrong type effects the link juice and your SEO.
There are 8 different redirect status codes:
- 301 Moved Permanently - Permanently redirect a URL and pass the link juice.
- 302 Moved Temporarily - Does not pass link juice, a 302 and is only a temporary redirect.
- 303 See Other - You will often see a 303 after submitting form data. The redirect sends a user to the results after submitting data.
- 304 Not Modified - Tells the browser that the resource has not changed, do not download again.
- 305 Use Proxy - Redirects the browser to use a proxy server
- 306 Switch Proxy - This is no longer in use.
- 307 Temporary Redirect - Redirect temporarily but do not change the request type. It does not pass link juice.
- 308 Permanent Redirect - Like a 301, redirect permanently but do not change the request type. This does pass the link juice.
You have no reason to use 303, 304, 305 and 306. So you can ignore these for general page redirection.
You now have 4 options to choose from. 301, 302, 307 and 308.
- 301 and 308 are for permanent redirects that pass link juice.
- 302 and 307 are temporary redirects that do not pass link juice.
Which Redirect Should You Use?
So now we know what these redirects look like and whether they pass link juice.
Let’s take a look at common examples where you need to redirect a page and which status code you should use:
- You have a typo in the URL but there are already links to the page, in this case, use a 301 to redirect to the new page.
- You need to remove a page and you want to redirect links to a new page use a 301.
- You have moved where your “contact us” form sends data. As this uses a POST request and you want to move this permanently use a 308 status code.
- You have added SSL to your website and want all pages on the site to move from HTTP to HTTPS. Then using a 301 redirect to permanently redirect and pass link juice.
- You are down for maintenance and need to redirect users temporarily. Use a 302 to redirect users to the maintenance page.
- You want to redirect users to a webpage based on their location. This should use a 302 as this redirect is temporary.
- You want to redirect users to a webpage based on their device. This should use a 302 as this redirect is temporary.
- After submitting a form you want to redirect users based on their location, for this use a 307 status code.
This choice comes down to a simple one.
Do you want the redirect to be permanent or temporary?
If it is permanent, are you sending data? If you are, then use a 308 status code. If you are reading data then use a 301 status code.
The same goes for a temporary redirect.
If the temporary redirect is sending data then use a 307. If no data is being sent then use a 302 status code.
Let’s take a look at how we can do this.
Client or Server Side Redirects?
You can do 302 redirects on both the client and server-side. It is a good idea to do the redirects server-side as this is best for SEO. As it lets Google know about the redirection.
Yet, there are times when it is a good idea to do client-side redirection. An example is after a user has logged in.
Let’s look at a few common ways to do client-side redirection.
For example, if we had a page at:
And we needed to redirect it to:
We would add a meta tag to the old page like this:
<meta http-equiv="refresh" content="5; URL=https://example.com/new-page.html">
This will cause the page to redirect using a 302.
// Option A
location.href = "https://example.com/new-page.html";
// Option B
// Option C
Any of the above options would cause the page to redirect.
Remember, this is all happening client-side. In the user’s browser.
As I mentioned it is possible to do this server-side and it is the best choice in most cases. All web servers and CDN’s can redirect.
Each web server will have a different way of doing a redirect.
For example, in Wordpress you can perform a redirection like this:
wp_redirect( "https://example.com/new-page.html", 301 );
If you have a CDN it is also possible to redirect there.
For example, a CDN like Cloudflare can be set up to redirect using Page Rules:
The main takeaway here is that on the client side you can only use a 302 redirect.
All redirects 301, 302, 307 and 308 can be done server-side.
Wrapping Up, 302 vs 301 Redirect
We have looked at the available types of redirection.
An important SEO consideration is link juice and when you want it to pass to the new URL.
When you are deciding between a 301 or a 302 you need to decide if the redirection is permanent or temporary.
If it is permanent then use a 301.
If it is permanent and you are sending data using a POST request then use a 308.
If it is temporary then use a 302.
If it is temporary and you are sending data using a POST request then use a 307.
301 and 308 will pass link juice.
302 and 207 will not.
Remember that you can perform a 302 redirect client-side. But, only do this if you have to.
We recommend doing all redirects server-side using your web server or CDN.