Tips & Tricks: 3 IIS7 URL Rewriting Rules for Improved SEO

Thursday, August 6, 2009

iis7 If you are a regular reader of this blog then you probably noticed that the design and layout has changed considerably. The fact is that the changes actually go much deeper than that, as I’ve gone as far as switching the platform entirely. I recently decided to explore other Open Source platforms, and the final choice of blogging platform chosen is BlogEngine.net. I will be sharing my reasons and thought process about this change (and others in the works for other application types) in another blog post.

When moving a blog there are several things that need to fall in place in order to make the transition as smooth as possible. SEO sits high on the priority list, so I started with the task of tweaking the blog’s URL rules.

For this task, since my application servers run IIS 7, I decided to give its freely distributed URL Rewrite extension and give it a fair shot. For your convenience, Microsoft has made the extension available through the Microsoft Web Platform Installer, so getting it up and running is a snap.

Once installed, open the IIS Manager where you should now see the newly installed extension under each of your websites, as shown below:

iis7-url-rewirte

Please note that this post does not only apply to blogs and BlogEngine.net; you can, and should apply these rules on any website requiring the full benefits of SEO.

In this blog post I will be discussing the 3 rules that I consider the most important when it comes to ensuring that your content is being indexed efficiently.

The screen shot below shows the list of rules as displayed in IIS Manager after they have been defined.

iis7-url-rewirte-rule-list

Convert/Force URLs to Lower Case

URLs can be defined in both uppercase and lowercase characters. What this means is that http://www.cto20.com/post/one-function-to-rule-all-urls.aspx is treated as a different page than http://www.cto20.com/post/One-Function-To-Rule-All-URLs.aspx by a search engine, even though they point to the VERY SAME resources and content. The best way to handle this issue is to REWRITE the URL to lowercase and respond to the “old” capitalized version with am HTTP 301 response (Permanently moved).

Here is the rule:

 

<rule name="Convert to lower case" stopProcessing="true">  
	<match url=".*[A-Z].*" ignoreCase="false" />  
	<action type="Redirect" url="{ToLower:{R:0}}" redirectType="Permanent" />
</rule>

 

Below is a screen shot of the Edit Rule UI in IIS for the lower case enforcement rule:

iis7-url-rewrite-lowercase-rule

 

Enforce Canonical Host Names

Similar to what we described above, search engines will treat http://www.cto20.com and http://cto20.com as two separate websites. Search rankings are surely going to drop, given that search engines believe that 2 sites should share the benefit of having the same content.

Once again, the solution is quite simple: HTTP 301 Redirect http://cto20.com to http://www.cto20.com.

Note that the rule below includes additional conditions for the antoniochagoury.com domain name, which also points to this blog. In this case, I added two additional conditions where I HTTP 301 redirect all requests to antoniochagoury.com whether prefixed with a www. or not.

 

<rule name="Canonical Host Name" stopProcessing="true">  
	<match url="(.*)" />  
	<conditions>  
		<add input="{HTTP_HOST}" negate="true" pattern="^cto\.com$" />
		<add input="{HTTP_HOST}" negate="true" pattern="^antoniochagoury\.com$" /> 
		<add input="{HTTP_HOST}" negate="true" pattern="www.antoniochagoury\.com$" /> 
	</conditions>  
	<action type="Redirect" url="http://www.cto20.com/{R:1}" redirectType="Permanent" />  
</rule>

 

Below is a screen shot of the Edit Rule UI in IIS for the canonical host names enforcement rule:

iis7-url-rewrite-canonical-rule

Even More Canonical Host Name

Similar to what we described above, search rankings will suffer and drop, if search engines believe that 2 sites share the same content.  Incidentally, search engines also think that http://www.cto20.com and http://cto20.com/default.aspx  are two separate websites. The right thing to do here, is HTTP 301 redirect the default.aspx page to http://www.cto20.com by applying the following rule.

 

<rule name="Canonical Host Name - Redirect Default.aspx" patternSyntax="Wildcard" stopProcessing="true">
	<match url="default.aspx" />
	<action type="Redirect" url="/" redirectType="Permanent" />
</rule>

Below is a screen shot of the Edit Rule UI in IIS for the canonical host names enforcement rule for the default.aspx option:

 

iis7-url-rewrite-canonical-rule2

All rules described above are applied to this blog site. You can verify the rules using the test cases below:

More information and reference for version 2.0 of the URL Rewrite extension, can be found here: http://learn.iis.net/page.aspx/665/url-rewrite-module-20-configuration-reference/

Comments

trackbackPimpThisBlog.com said:

CTO 2.0 | Tips & Tricks: 3 IIS7 URL Rewriting Rules for Improved SEO

Thank you for submitting this cool story - Trackback from PimpThisBlog.com

article directoryUnited Kingdomarticle directory said:

Thanks. This is a really useful post about blogengine.net.  I've got a test system up and running on my dev environment, almost ready to go live! Smile

Steve SUnited StatesSteve S said:

I want to do sth like this in iis7 web.config:

if, no query string attached in http://www.domain.com/index.aspx" rel="nofollow">http://www.domain.com/index.aspx then redrected to http://www.domain.com/

else, keep the query string like http://www.domain.com/index.aspx" rel="nofollow">http://www.domain.com/index.aspx?test=23123&whatever

How to do that? Can you help? Thanks.

Steve SUnited StatesSteve S said:

I want to do sth like this in iis7 web.config:

if, no query string attached in domain_name/index.aspx then redrected to domain_name

else, keep the query string.eg. domain_name/index.aspx?test=23123&whatever

How to do that? Can you help? Thanks.

JessieMalaysiaJessie said:



Hi,

I want to create subdomain rewrite from the following url:
http://www.domain.com/MyPage.aspx?url=myname
to
http://myname.domain.com/Testing/

So, I create a new rules using blank rule,

<rule name="TestPage" enabled="true" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{HTTP_HOST}" pattern="^([A-Za-z0-9_]+)\.domain\.com/Testing/" />
                    </conditions>
                    <action type="Rewrite" url="MyPage.aspx?url={C:1}" />
                </rule>

When i browse the page (http://myname.domain.com/Testing/), i can't go to the exact page which is (http://www.domain.com/MyPage.aspx?url=myname) .

Is my rule or pattern correct? Can anyone give me some guidelines or examples what I should add in my rules(e.g: Pattern in Match URL, Conditions & Action)?

Thanks.

LouisUnited StatesLouis said:

Thank you so much.  I was using Helicon's filter on IIS6 but upgraded to IIS 7 and forgot my regex code for the default.aspx to / code.  You rock!

Carlos CanejaUnited StatesCarlos Caneja said:

This is an awesome post and 1st one I find that shows how to implement these rules via the GUI.

Thanks.

white sundressUnited Kingdomwhite sundress said:

Hey, Thanks for the useful post! I'm using Linux hosting. Is it applicable to Linux box?

<br>
Thanks<br>
Vinoth

Comments are closed