301 versus 302 website redirects

On a recent project I was working with a client and had to ask what was the goal with their multiple domains. In best case scenarios, developers only have one domain to worry about.  But in some instances there are multiple domains, old sites, and new sites – and that’s where  the management comes to play.  In this scenario, the client wanted to set up a temporary landing page (also known as a splash page), turn-off an old website, and maintain all of their domains.

So I had to decided, do I want to redirect all sites to one domain, or host the domains with a singular directory.  Since time, domains were hosted with various providers, resources were a factor (and usually is) I decided to use the forwarding process.  But with forwarding, there are 2 options that usually aren’t discussed in detail – and using the wrong one can be costly long term.

A 301 redirects the client to the specified URL with a “301 Moved Permanently” HTTP response. The Status 301 means that the resource (page) is moved permanently to a new location. Based on this response, the client/browser should not attempt to request the original location but use the new location from now on.  When a search engine spider finds 301 status code in the response header of a webpage, it understands that this webpage no longer exists, it searches for location header in response pick the new URL and replace the indexed URL with the new one and also transfer PageRank. The beauty of a 301 is, that you don’t lose your traffic from the old webpage.  Under the hood, the browser interprets a 301 status code and caches the mapping of the old URL with the new URL.

Usually companies do this when they change names, i.e. thefacebook.com to facebook.com.  If you permanently move or rename a file from one thing to another, i.e. domain.com/example.html to domain.com/asp-net-example. Or if you create several domains that may be a deviation of your main domain such as: gooogle.com.


<script>
private void Page_Load(object sender, System.EventArgs e){
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.mynewdomain.com");}
</script>

On the other side of the coin, a 302 redirect (Status 302) sends a ‘302 Found” HTTP response to the client.  The Status 302 means tells the user agent that the resource (page) is temporarily located somewhere else, and the client/browser should continue requesting the original url.  When a search engine spider finds 302 status for a webpage, it will only redirect temporarily to the new location and crawl both of the pages. The old webpage URL still exists in the search engine database and it always attempts to request the old location and crawl it. The client/browser will still attempt to request the original location.


<script runat=”server”>
private void Page_Load(object sender, System.EventArgs e){
Response.Status = “302 Found”;
Response.AddHeader(“Location”,”http://mynewdomain.com/we-are-here.asp”);}
</script>

You can can achieve the proper redirect in most programming languages such as PHP, Java, or ASP.Net. You can also achieve it from within .htaccess file or from IIS.  And you can always remove the redirect.

 

I don’t do what you do, and you don’t see what I see Therefore we could not be the same, do you feel me? I come from Tennessee and love drinkin’ Hennessy Peace to KRS, but here’s my philosophy