• Home /
  • Blog /
  • SEO improvements for Orchard CMS ASP.NET MVC website

SEO improvements for Orchard CMS ASP.NET MVC website

I am very focused on excellent search engine optimization for websites which I develop for my clients, so during the years of my work with ASP.NET MVC I developed a number of helpful rewrite rules for IIS using web.config

The information below can be applied to any ASP.NET MVC website, not only to Orchard CMS.

Rewrite rules located in your web.config file in system.webServer section.

IIS Rewrite rule to redirect from www domain

I did a research about using www in your domain name and the result was that it is not require, and just obsolete, so for all websites I create I redirect users from www domain to non www. The rule to do it below, please note you have to type url of domain there, so for your website you have to modify this rule.

  <rule name="Remove WWW prefix for com domain">
	<match url="(.*)" ignoreCase="true" />
	  <add input="{HTTP_HOST}" pattern="^www\.yaplex\.com" />
	<action type="Redirect" url="https://yaplex.com/{R:1}" redirectType="Permanent" />

IIS rewrite rule to convert to lowercase

When working with ASP.NET MVC website there are two options to make URL lowercase, both are described there Lowercase urls for Orchard CMS below I just provide IIS rule to redirect to lowercase url, for second option check another post

  <rule name="Convert to lower case">
	<match url="[A-Z]" ignoreCase="false" />
	<action type="Redirect" url="{ToLower:{URL}}" redirectType="Permanent" />
	  <add input="{URL}" pattern="^.*/admin" negate="true" />
	  <add input="{URL}" pattern="^.*/users" negate="true" />

IIS Redirect rule to remove trailing slash

In internet word the two urls https://yaplex.com/blog/ and https://yaplex.com/blog are different URLs, when working with most content management systems they allow redirect to one of this types or handle both types (with trailing slash and without) as the same URL, but for some CMS it's not true, for example Orchard CMS, but it can be fixed with following rule.

   <rule name="Remove trailing slash">
	<match url="(.*)/$" />
	  <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
	  <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
	<action type="Redirect" redirectType="Permanent" url="{R:1}" />

Redirect to https with IIS rewrite rule

It was not long time ago when Google announced about better ranking for https websites over http, but almost everybody now migrated to https. It is not difficult to migrate to https and with price drop for certificates it is more affordable than ever. The following rule will redirect all your traffic from http website to https

  <rule name="Redirect to HTTPS">
	<match url="(.*)" />
	   <add input="{HTTPS}" pattern="^OFF$" />
	  <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />

Static redirect rule for IIS

The last rule I have is for dead links or pages which moved to new url. I use a separate file which contain all my old links with a new location for the page and the following IIS rule will move traffic from old to new urls (this is a good idea for Orchard CMS module)

<rule name="static Redirect from map file">
  <match url=".*"/>
	<add input="{StaticRedirects:{REQUEST_URI}}" pattern="(.+)" />
  <action type="Redirect" url="{C:1}" redirectType="Permanent" />

The actual file tag located inside of <rewrite> tag in web config and looks like

<rewriteMaps configSource="rewrite-maps.config"/>

and actual file looks like

  <rewriteMap name="StaticRedirects">
    <add key="/services/web" value="/services/web-development" />
    <add key="/developer-resume" value="/resume" />
    <add key="/blog/developer-resume" value="/resume" />

The whole section of my web.config with all rewrite rules looks like this



Yaplex logo white text

Yaplex is an IT Consulting and .NET development company co-founded by .NET Developer Alex Shapovalov who lives in Mississauga and provides software development services in Toronto, Mississauga, and GTA.

Contact Information

Toronto, Canada
Phone: +1 647 328 3809