SEO: Canonical URLs and correct redirecting with 301

by alex 25. March 2013 21:05

I just finished setting up my canonical URLs and redirections for this domain and blog. If this is configured incorrectly your various pages may appear as two different sites to search engines.

Canonical URLs - what are they and why should you care?

Is your URL or Or are these the same site? If they're the same, is also the same? To most search engines, URLs with the www do not refer to the same content as those without the www sub domain.

That means, if you have links 'all over the internet' to both and, them these appear to be two different websites to search engines. Deciding on whether or not you will use www, and ensuring that all of your links include it, is part of the effort to make canonical URLs.

I don't remember ever reading a definition of this term that was worth writing home about, but here's my best shot after reading everything on the internet -

Canonicalization of URLs is the process of deciding the best URL to use for a given resource. A canonical URL, therefore, is the preferred URL to access a resource.

For example, these links could all refer to the same file, index.html stored in the wwwroot folder of a server:


There are a few negatives to not canonicalizing your URLs:

  1. Webcrawlers will hit your server multiple times for the same content
  2. Search engines will generally attempt to merge the rankings of similar URLs providing the same content (e.g., and, but if they can't automatically resolve the duplication, the ranking of your content may be distributed between multiple URLs.

That bears repeating. If you don't have your URLs setup properly then search engines may dilute your page's ranking by distributing it across multiple URLs.

Do you add the www or remove it? There are fights on both side of this argument, but for all it's worth, this decision might as well just come down to aesthetics.

After you make the decision of how links to your site should look, you need to change all of your internal links to use the canonical format. That just means that you have to make sure that you always include the www or you always omit it. If you have any other resources that are available through multiple sources (for example, the Home controller and the Index action for ASP.NET MVC projects), make sure to also always link to these via the same URL.

I've always elected to include the www. This means that will return a permanent redirect (301) indicating the content is located at To see a sample of this, open - your browser will automatically redirect to Additionally, I don't have anything in the root of this domain at this point, so I want to redirect to my blog subfolder.

To achieve these goals, I added the following snippet to my web.config file, located in the wwwroot folder:

			<rule name="Redirect non-www to www - loses path info" patternSyntax="ECMAScript" stopProcessing="true">
				<match url=".*" />
					<add input="{HTTP_HOST}" pattern="^$" />
				<action type="Redirect" url="" />
			<rule name="Redirect root to blog" stopProcessing="true">
				<match url="^$" />
				<action type="Redirect" url="" />

These rules direct IIS to return 301, permanent redirects for the the following URLs. If I navigate to any of these URLs, the browser is automatically redirected to my canonical URL,


Later, when I have content for the root site, I'll remove the "redirect root to blog" rule.

I'll comment on this later, but this post only dealt with top-level canonicalization. These URLs also need to be canonicalized if they serve the same content:


Add comment

  Country flag

  • Comment
  • Preview

About the author

Something about the author

Month List