Problem

I was asked to look at a Sitecore solution, where it was not possible to show a custom application in the sitecore client. In fact it was not possible to show a number of the standard dialog’s, for example the presentations dialog (see the image above).

It was strange as some dialog’s worked and others did not, so I opened the developer tools which immediately showed me what the issue was.

As you can see a lot of stuff is missing? This is because Sitecore’s HTTP handler is looking for URL’s that begin with “WebResource.axd” and it is case sensitive.

Rewrite Rules Strike Again

To improve SEO, the following rewrite rule was introduced in the web.config to lower case ALL url’s

Now whilst this was great for the websites SEO; it was responsible for breaking the sitecore client as there are a number of URL’s which are case sensitive.

Solution

The solution was to identify all the case sensitive sitecore client URL’s and exclude them from the lowercase rule.

Now instead of trying to write the most complex regular expression ever, which would catch all the website URL’s and avoid all the Sitecore client calls.

I decided to add an individual condition match pattern for each (URL) and then used the negate=true to exclude the URL from the redirect rule.

Thanks to M for following version which fixes issues relating to the path and query strings being stripped, from the URL.

<rewrite> <rules> <!-- https://blog.coates.dk/2018/01/15/lower-casing-rewrite-rules-breaks-the-sitecore-client/ --> <!-- Take redirectType="Temporary" out of production --> <rule name="LowerCaseRule - not including querystring" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{PATH_INFO}" pattern=".*[A-Z]" ignoreCase="false" /> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" /> <add input="{REQUEST_URI}" pattern="^/(sitecore)" negate="true" /> <add input="{REQUEST_URI}" pattern="^/(sitecore modules)" negate="true" /> <add input="{REQUEST_URI}" pattern="^/-/" negate="true" /> <add input="{REQUEST_URI}" pattern=".*(-/media).*" negate="true" /> <add input="{REQUEST_URI}" pattern=".*(~/media).*" negate="true" /> <add input="{REQUEST_URI}" pattern=".*(~/icon).*" negate="true" /> <add input="{REQUEST_URI}" pattern="WebResource.axd" negate="true" /> <add input="{REQUEST_URI}" pattern="ScriptResource.axd" negate="true" /> <add input="{REQUEST_URI}" pattern="jsnlog.logger" negate="true" /> <add input="{REQUEST_URI}" pattern="Telerik.Web.UI.WebResource.axd" negate="true" /> <add input="{REQUEST_METHOD}" matchType="Pattern" pattern="POST" ignoreCase="true" negate="true" /> </conditions> <action type="Redirect" url="/{ToLower:{R:1}}" appendQueryString="true" redirectType="Temporary" /> </rule> </rules> </rewrite>

Ignore POST requests

Thanks to Søren Kruse for pointing this out; The redirect will change a POST requests to a GET and you will lose any data in the body of the original request. Therefore you should ensure that POST requests are not redirected.

<add input="{REQUEST_METHOD}" matchType="Pattern" pattern="POST" ignoreCase="true" negate="true" /><span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start"></span>

Well I hope this helps, Alan