301 vs 302

May 7, 2019 arnold.sebastian

I get this question quite a lot:

What is the difference between 301 and 302?

Introduction to response codes

So before I want to answer this let me first explain when this code is used. This is a status response when you request a URL from a website. Normally is all goes well the response will be 200, if the page is not there it will be 404.

The last one you want to make sure you do not get. Search engines do not like it if they point to a webpage and it is gone without a trace. This is where 301 or 302 comes in.

So how do 301/302 codes work?

We usually use this when we did a website upgrade and the URL structure has changed.

For example on the old website the URL for the contact form is :

OLD: https://yourdomain.com/content/contact-us

NEW: https://yourdomain.com/contact-us

If you just change the URL address of that page without leaving a trace where it went the search engine like Google will be disappointed. Just like your friends would be when you change your phone number and you do not give them your new number.

So this is where we use the 301 and 302 status.

301: We have moved to a new location.

302: We have moved temporarily to a new location.

So this would look for the search engine something like this:

https://yourdomain.com/content/contact-us – 301 We have moved to https://yourdomain.com/contact-us

https://yourdomain.com/content/contact-us – 302 We have temporarily moved to https://yourdomain.com/contact-us but we will go back to the old address soon.

So you see now that the search engine will now know what to do, and as a free bonus, your normal website visitor will be redirected to the right place as well without them ever felt left behind.

So now how could you implement this?

Sorry, we are now getting a bit more technical but we will do a simple introduction first. If you want any other examples please leave a comment and I would be happy to show you have to do it.

So the way we are going to introduce now is using the .htaccess file. This a hidden file in your website route the webserver like Apache uses to handle your website requests.

So for our 301 example: 
https://yourdomain.com/content/contact-us – 301 We have moved to https://yourdomain.com/contact-us

We would edit our .htaccess file to look something like this:

<IfModule mod_rewrite.c>
RewriteEngine On
Redirect 301 /content/contact-us /contact-us

</IfModule>

And for our 302 example: 
https://yourdomain.com/content/contact-us – 302 We have temporarily moved to https://yourdomain.com/contact-us but we will go back to the old address soon.

We would edit our .htaccess file to look something like this:

<IfModule mod_rewrite.c>
RewriteEngine On
Redirect 302 /content/contact-us /contact-us

</IfModule>

Hopefully, these examples will help you to get started and make sure you do not lose that expensive organic traffic that has cost you so much time to get.

If there are any questions or comments please use the comment function below and I will get back to you as soon as I can.

About Sprout

We are a digital consultancy company that specializes in end to end mobile app development, web development, and e-commerce services. We can also help you set up your product and technology department.

 

 

 

 

Comment (1)

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact

Get Connected.

We welcome you to contact us for more information
about any of our products or services.

We would love to talk to you!

Let's have some coffee

Whatever the project is you want us to work on, or whatever problem you have. Please reach out to us! We would love to talk to you and learn more about how we can help you.

Every project is different and we want to translate your wishes in a solution that makes or saves you money. From Web Development, Mobile Development to full end to end projects we are looking forward to starting this journey with you.

CALL: +62 21 30032327

Contact