Tom Lauck’s

IIS 7, SEO, and You: Part 1 – URL Rewriting


If you currently do not take a technical interest in Search Engine Optimization (SEO) as a developer, you should.  As opposed to Search Engine Marketing (SEM), an effective SEO plan can often only be implemented by a developer becuase of it’s technical nature.  One such optimization is url rewriting.  A few minutes spent searching on Goolgle will uncover what has been going for years in the Apache world with mod_rewrite and .haccess.  The great thing about mod_rewrite is that you have full control over url structure, and essentially the way search bots crawl through your site.  Many have termed .htaccess/mod_rewrite as “the Swiss Army Knife of SEO.”

Some basic rules that most optimiztion plans include is redirecting to a canonical domain, adding a trailing slash, and removing file extensions. Since II7 natively supports url rewriting now, achieving is very straightforward. There are number of methods to do this, but one way is adding some rules to your Web.config file.

Sample rules for cannonical domain redirect, trailing slash, and file extension:

		<rule name="Redirect To Cannonical Domain" stopProcessing="true">
			<match url="^(.*)$" />
				<add input="{HTTP_HOST}" pattern="!^example\.com" />
			<action type="Redirect" url="$1" redirectType="Permanent" />
		<rule name="Remove Index Pages" enabled="true" stopProcessing="true">
			<match url="(.*)(index|default)\.(asp|aspx|html|htm)$" />
			<action type="Redirect" url="{R:1}" appendQueryString="true" />
		<rule name="Add Trailing Slashes" enabled="true" stopProcessing="true">
			<match url="^([^.?]+[^.?/])$" />
			<action type="Redirect" url="/{R:1}/" redirectType="Permanent" />
		<rule name="Remove File Ext Reverse" enabled="true" stopProcessing="true">
			<match url="^(.+)\.aspx$" />
				<add input="{REQUEST_METHOD}" negate="true" pattern="^POST$" />
			<action type="Redirect" url="/{R:1}/" appendQueryString="true" redirectType="Permanent" />
		<rule name="Remove File Ext" stopProcessing="true">
			<match url="^(.+)/$" />
				<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
				<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
			<action type="Rewrite" url="/{R:1}.aspx" appendQueryString="true" />

Avoiding duplicate content (http://www vs http:// or /pathtofile/ or /pathtofile), reducing Search Engine Ranking Page (SERP) ranking drops with a relaunch or update, and over solid URL structure are just some of the benefits of a good URL rewriting scheme.  Now that IIS 7 has a URL Rewrite as built in component, web applications built on .NET can be ever more powerful.  In the next part of the series, we will look at the new beta of the Search Engine Toolkit for IIS 7.

Jun 10 2009