How To Do A 301 Redirect

There are both simple and complicated ways to do 301 redirects. As we like to keep things simple, we like to do 301 redirects either directly from domain registrar, or from cpanel if you have the website hosted somewhere already.

If you need specific direction on how to do a redirect with your specific registrar, just google “301 redirect registrar”.

For example some common registrars are Namecheap and Godaddy. Here is what I got when I Google’d “301 redirect namecheap” and “301 redirect godaddy”:

Namecheap: https://www.namecheap.com/support/knowledgebase/article.aspx/385/2237/how-do-i-set-up-a-url-redirect-for-a-domain

Godaddy: https://www.godaddy.com/help/using-301-page-redirects-234

Also if you have a site on WordPress, one of our favorite plugins to use (which we use on this site actually) is one called “Simple 301 Redirects”.

It’s as easy as searching for it, installing it, activating it and using it. To use it you just simple plugin the old URL, plugin the new URL, and then hit save. That’s it!

If you are a techie that is into the more complicated methods, they are listed below!

Apache Web Server .htaccess file

Apache .htaccess files let you override the Web server configuration on a per-directory hierarchial basis, and are instrumental in the creation of proper 301 redirects. For more information, consult the Apache .htaccess Tutorial and the Apache URL Rewriting Guide.

Single Page Redirect:

Redirect 301 /old/url /new/url

or

Redirect Permanent /old/ur /new/url

 

Canonical Hostname Redirect (non-www to www):

This solution will redirect any page requested via a non-www domain to the same URL with the www domain, and as such it can be placed in the DocumentRoot of your site and will be enforced globally:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]


Microsoft IIS Web Server

Note: these instructions require administrative access to IIS. If you do not have this access (e.g., if you have a shared hosting account on a Windows server), you should use one of the server-side scripting methods such as ASP or PHP given further below.

Single Page Redirect:

  1. Open Internet Services Manager and right-click on the file or folder you wish to redirect.
  2. Select the radio button “a redirection to a URL”.
  3. Enter the desitnation page for the redirect.
  4. Check “The exact url entered above” and the “A permanent redirection for this resource”.
  5. Hit “Apply”.


PHP 4 and PHP 5

Single Page Redirect:

<?php
header(‘HTTP/1.1 301 Moved Permanently’);
header(‘Location: http://www.new-url.com/’);
?>

 

Canonical Hostname Redirect (non-www to www):

<%
If InStr(Request.ServerVariables("SERVER_NAME"),"www") = 0 Then
      Response.Status="301 Moved Permanently"
      Response.AddHeader "Location","http://www." & Request.ServerVariables("HTTP_HOST") & Request.ServerVariables("SCRIPT_NAME")
      Response.End
End if
%>


Active Server Pages (ASP)

Single Page Redirect:

<%
Response.Status=”301 Moved Permanently”
Response.AddHeader=’Location’,’http://www.new-url.com/’
%>

 

Canonical Hostname Redirect (non-www to www):

This code should be inserted into a global include file or any ASP script which is executed for every page on the site before the page output begins:

<%
If InStr(Request.ServerVariables("SERVER_NAME"),"www") = 0 Then
	Response.Status="301 Moved Permanently"
	Response.AddHeader "Location","http://www."
		& Request.ServerVariables("HTTP_HOST")
		& Request.ServerVariables("REQUEST_URI")
	Response.End
End if
%>


ColdFusion

Single Page Redirect:

<cfheader statuscode=”301″ statustext=”Moved permanently”>
<cfheader name=”Location” value=”http://www.new-url.com/”>
In Category: Uncategorized

This Is An Example Title

Free Website Analysis

Greg

Show 0 Comments
No comments yet. Be the first.

Leave a Comment