Udostępnij za pośrednictwem


SEO made easy with IIS URL Rewrite 2.0 SEO templates

A few weeks ago my team released the version 2.0 of the URL Rewrite for IIS. URL Rewrite is probably the most powerful Rewrite engine for Web Applications. It gives you many features including Inbound Rewriting (ie. Rewrite the URL, Redirect to another URL, Abort Requests, use of Maps, and more), and in Version 2.0 it also includes Outbound Rewriting so that you can rewrite URLs or any markup as the content is being sent back even if its generated using PHP, ASP.NET or any other technology.

It also includes a very powerful User Interface that allows you to test your regular expressions and even better it includes a set of templates for common types of Rules. Some of those rules are incredibly valuable for SEO (Search Engine Optimization) purposes. The SEO rules are:

  1. Enforce Lowercase URLs. It will make sure that every URL is used with only lower case and if not it will redirect with a 301 to the lower-case version.
  2. Enforce a Canonical Domain Name. It will help you specify what domain name you want to use for your site and it will redirect the traffic to the right host name.
  3. Append or Remove the Trailing Slash. It will make sure your request either include or not include the trailing slash depending on your preference.

image

For more information on the SEO Templates look at: https://learn.iis.net/page.aspx/806/seo-rule-templates/

What is really cool is that you can use the SEO Toolkit to run it against your application and you probably will get some violations around lower-case, or canonical domains, etc. And after seeing those you can use URL Rewrite 2.0 to fix them with one click.

I have personally used it in my Web site, try the following three URLs and all of them will be redirected to the canonical form (https://www.carlosag.net/Tools/CodeTranslator/) and you will see URL Rewrite in action:

  1. https://www.carlosag.net/Tools/CodeTranslator/
  2. https://carlosag.net/Tools/CodeTranslator/
  3. https://www.carlosag.net/Tools/CodeTranslator

Note that at the end those templates just translate to web.config settings that become part of your application that can be XCOPY with it. This works with ASP.NET, PHP, or any other server technology including static files. Below is the output of the Canonical Host Name rule which I use on my Web site’s web.config.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="CanonicalHostNameRule1">
                    <match url="(.*)" />
<conditions>
                        <add input="{HTTP_HOST}" pattern="^www\.carlosag\.net$" negate="true" />
</conditions>
                    <action type="Redirect" url="https://www.carlosag.net/{R:1}" />
</rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

There are many more features that I could talk, but for now this was just a quick SEO related post.

Comments

  • Anonymous
    April 01, 2010
    This is especially good for the case problem- I used to have a nightmare managing large e-commerce sites where the upper and lower case url's were all mixed up.
  • Anonymous
    April 05, 2010
    Hey Carlos,  We met at the xMS SEO Summit in Redmond a few weeks back.  I'm back in Sydney, Australia now but I came across this post and wanted to say "Thank You" it's a great blog post, and I have passed it onto our dev team.Also, just wanted to say - I'm loving the IIS SEO Toolkit - Nice work :)   Please add me to a Beta Announcement list (if there is one).Regards,Mark Vozzo - Microsoft Australia
  • Anonymous
    April 06, 2010
    Hello,   We suggest putting Permanent redirect in the code:               <rule name="www" enabled="true" stopProcessing="true">                   <match url="(.*)" />                   <conditions logicalGrouping="MatchAll">                       <add input="{HTTP_HOST}" negate="true" pattern="^www.elstir.com$" />                   </conditions>                   <action type="Redirect" url="http://www.elstir.com/{R:1}" redirectType="Permanent" />               </rule>More info in Spanish at:http://www.elstir.com/contenido/nombres-canonicos-para-paginas-web
  • Anonymous
    April 06, 2010
    Very nice article.. worth reading it. Thank you for posting such a nice post about seo :D
  • Anonymous
    June 14, 2010
    @RubenS  Permanent redirect is the default in URL Rewrite so it is optional to add the type=Redirect. In the rule above it will be a permanent 301
  • Anonymous
    October 01, 2010
    Doh! - i did not select a website first and was unable for hours of removing and re-installing the software - to see the SEO Templates....  Context:GlobalorWebsite Level   -must select the website first then url rewrite
  • Anonymous
    October 03, 2010
    I have a lil question about that.I need to remove all double or more slashes '///' of my url ends. My links are ok but external links from other website are not. wat rle can i use in my web.config to do that.Thanks a lot.
  • Anonymous
    July 13, 2013
    This is certainly a great blog post a few years later!http://www.torontoseogurus.com