Get Quote

Name *

Phone No *

Email *

Website

Services *

Message

Monthly budget:

Referral

Enter the characters:
captcha


Free Account
Phone Number
Watch Company Video

301 Canonical Redirects

A 301 canonical redirect is a way to get all of the web pages on a site to point to a certain address. For instance, if you wanted all of your non www-prefix pages going to pages with a www prefix, you would use a 301 canonical redirect. A more concrete example would be taking the page http://something.com and redirecting it to http://www.something.com. This is the 301 redirect part. Canonicalization allows all pages to point to other sites. For instance, a 301 canonical redirect could point all pages with the format http://something.com/morestuff to http://www.something.com/morestuff.

So why would anyone want to do this? From an SEO perspective, this is a very important optimization technique. Search engines don’t look at non-www prefix websites and their corresponding www-prefix sites as the same. If people place links to each of these URLs then you are in essence building a link campaign for different URLs. 301 redirects centralize these pages and allow all link juice to go to a central page.

There are various techniques to achieving a 301 redirect depending on the type of website or the server the website is on. If the website is hosted on an Apache server, one needs to access a file called .htaccess and modify with the following code:

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

In most cases this will work. It will not work on a website hosted on an IIS (Microsoft) server, however. If this is the case, one can add the following javascript code to the global header or footer to achieve the same effect:

<script type="text/javascript">
var pathd="http://www.moorenonprofitlaw.org"+location.pathname+location.search;
if (location.hostname.substring(0,3) != ''''www'''')
window.location.href=pathd;

But be forewarned. Some search engines such as Google do not understand Javascript and will therefore not help you with you SEO efforts. According to Google Webmaster Help:

"When a redirect link is embedded in Javascript, the search engine indexes the original page rather than following the link, whereas users are taken to the redirect target. Like cloaking, this practice is deceptive because it displays different content to users and to Googlebot…"

If you page is an ASP page, you can use the following redirect code:
<%
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
%>

Or the following if it is an ASP.NET page (I’ve found that the redirect only works if interested right after an <html> tag):

<script runat="server">
protected void Application_BeginRequest(Object sender, EventArgs e)
{
HttpApplication app = sender as HttpApplication;
string domainName = "example.com";

if (app != null)
{
string host = app.Request.Url.Host.ToLower();
string requestUrl = app.Request.Url.PathAndQuery;

if (String.Equals(host, domainName))
{
Uri newURL = new Uri(app.Request.Url.Scheme +
"://www." +
domainName +
requestUrl);

app.Context.Response.RedirectLocation = newURL.ToString();
app.Context.Response.StatusCode = 301;
app.Context.Response.End();
}
}
}
</script>

If you want to add code to a .php file, the following should work:
<?php

if (substr($_SERVER[''''HTTP_HOST''''],0,3) != ''''www'''') {
header(''''HTTP/1.1 301 Moved Permanently'''');
header(''''Location: http://www.''''.$_SERVER[''''HTTP_HOST''''.$_SERVER[''''REQUEST_URI'''']);

}
?>

There are several different ways to achieve the 301 canonical redirect and sometimes it takes some code tweaking to get it to work properly, but this is a start.

, , ,

Locations


Corporate Office
2265 E. 25th St.
Idaho Falls, ID 83404
1 Yonge St. Suite 1801 Toronto Star Building, Toronto, ON M5E 1W7 Canada
Sales Office
838 S 350 W
Lehi, UT 84043
20 Manton Ln Bedford Bedford Borough MK417, UK
Northbank Plaza, Level 22, 69 Ann Street Brisbane, QLD 4000, Australia

Learning Center


Is your business in need of internet marketing or website development, but you don't currently have the budget to hire a professional company like Netmark? Well you're in luck. Netmark has spent hundreds of hours creating special training so that people like you can also get access to great tips, strategies, and special training. Enjoy!

Contact Information


(800) 935.5133 – toll free
(208) 522.1016 – local
(208) 621.0227 – fax

Email
Netmark Website