Tuesday, April 19, 2016

Sitecore and IIS URL Rewrite module

    URL Rewrite is quite popular IIS module. It is SEO tool that allows you to improve site crawling by search engines. You can do a lot of things using it:
  • Add or remove trailing slash
  • Enforce lower case URLs
  • Use canonical hostnames
  • Redirect to HTTPS
  • etc.
    But it should be used very carefully with big systems, where you are unable to control everything. As example I'll show which problems could cause thoughtless URL rewrite configuration with Sitecore. The example that is given below correspond only to configuration CM and CD on one machine, otherwise you are free to configure URL rewriting on CD, but don't do anything on CM.

    Simplest URL rewriting rule is "Remove Trailing Slash". You can add this rule by using predefined templates inside IIS embedded wizard.
  

    This rule redirect all requests from "http://yourawesomewebsite.com/page1/" to "http://yourawesomewebsite.com/page1". It helps to avoid of indexing one your page twice, wrong resolving it by analytics, etc. But URL Rewrite rules has one bad feature, while redirecting they transfer POST request to GET. Let see how it can breaks Sitecore functionality.

Sitecore 8 has List Manager Lanchpad  application. It uses MVC approach for communication client with server. And as good MVC practice controller action are marked with method attributes. Delete list, delete folder, move list and others are marked only with [HttpPost] attribute. They do not allow [HttpGet]. And unfortunately client side JavaScript code call this method with trailing slash. E.g.:

http://yourawesomewebsite.com/sitecore/api/ssc/ListManagement/Actions/%7B0264829E-6680-49EB-85B8-703EF9414BA5%7D/DeleteListById/

URL Rewrite module will remove trailing slash and translate this request from POST to GET. As result we will get error:



How this issue could be solved:
  1. Do not use URL Rewrite module with complex website which work you could not fully control. Or use only with a part of site that you fully control. It is CD part for Sitecore.
  2. Rewrite URL Rewrite rule. In our example it could be "^(((?!ListManagement).*)/$" instead of standard "(.*)/$"  
  3. Use URL Rewrite module alternatives, as example ISAPI_Rewrite

No comments:

Post a Comment