How to change all URLs to lowercase in Orchard CMS

Orchard CMS URLs are not case sensitive, so the URL https://yaplex.com/blog and URL http://yaplex.com/BLOG are the same for Orchard, but not the same for search engines, like google, so it's hurting your SEO to have the same page accessible on multiple URLs.

Orchard does not have any mechanism to convert all URLs to lowercase, but due to the fact than Orchard CMS is an ASP.NET MVC application, this can be done with URL rewrite rule + change setting for route and instructing Orchard to lowercase all existing URLs.

Redirect to lowercase URLs using IIS URL Rewrite rule

Let's start with URL Rewrite rule, you need to modify web.config file and add the following


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

Now if you type https://yaplex.com/BLOG, you will be automatically redirected to https://yaplex.com/blog

But this is only partially solved our issue, because if you try to login to admin console and navigate to Dashboard, it is not going to work, because Admin section does not support lowercase URL and website goes to infinity loop (uppercase -> lowercase -> uppercase....)

How to produce lowercase URLs in ASP.NET MVC

To fix this, we need to instruct ASP.NET MVC to use lowercase URLs, open Global.asax.cs file and set lowercase property for routes to true;


public static void RegisterRoutes(RouteCollection routes) {
	routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
	routes.LowercaseUrls = true;
}

Why do we need both fixes, instead of just only one of this?

The fix which instructing ASP.NET MVC routing to produce lowercase URLs does not redirect to lowercase, it's just letting ASP.NET MVC know than all URLs which are generated, should be in lowercase format, for example all URLs in navigation menu will be lowercase. But you still can type upper case URL and it will work and open your page, so technically you still have two versions of the same page. That is why we need to do 301 redirect for all existing uppercase pages to lowercase format using IIS URL Rewrite module. In that case we instruct google or any different search engine than our page is available only on single lowercase URL



Comments

Social media

Search

Latest Tweets