301 & 302 Redirects




Description

Correctly redirecting pages is important in SEO. The two main redirect status codes are 301 and 302: respectively permanent and temporary redirects


Example

app.get("/de/folder/page", function(request, response) {
    response.writeHead(301, {
        Location: "https://newtargetpage.com",
    Expires: new Date().toGMTString()
    });
    response.end();
});


app.get("/de/folder/page", function(request, response) {
    response.writeHead(302, {
        Location: "https://newtargetpage.com",
        Expires: new Date().toGMTString()
    });
    response.end();
});
    

Redirects can be set up via an entry in the htaccess file of the Apache server.This is a small text file that contains instructions for the server. If a client calls a URL that is to be redirected, the server receives the command to redirect the client to the new URL. The .htaccess file is loaded from the server each time a page is accessed.



Redirect /old-path/new.html /newpath/new.html

####All site to new site:
Redirect 301 / https://newdomain.com/

#####Removing www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com
RewriteRule (.*) https://example.com/$1 [R=301,L]




When to use a 301 Redirect

A 301 redirect is the most used redirect for SEO purposes. It ensures that one URL is permanently forwarded to another. The redirection forwards Link juice from the old to the new URL but also contrary to a 302 redirect the final URL is cached. The redirect should be in place at least till the new URL is indexed. For a Domain transfer or encrypting the website with an SSL Certificate. New Site structure with new directories. Relocation of individual pages. These are not optimum if other global redirects are also in place. It is important to avoid redirect chains.


When to use a 302 redirect

The 302 is for temporary redirects so make sure you are using the correct one. These are useful for instance if a product or service is not available / out of stock for a limited time or if it is seasonal. There are many other possible uses such as testing a new page.


301 & 302 Redirects and SEO

When crawling the site, redirects should be reviewed. Some of the checks are looking for redirects chains or redirect loops, incorrect type of redirect. But redirects are mostly used to fix issues such as broken backlinks or duplicate content.









Alex Bieth, Owner @ SEO Berlino and SEO Consultant