IIS rewrite rule breaks CMS backend

Vote:
 

Hi Guys,

i have 2 IIS rewrite rules added for adding trailing slash and for changing uppercase letters in url to lowercase.. like so.

Everything works in de front-end, but opening the CMS, it breaks. 

Opening fiddler is get all 404 on resources starting with episerver/ and utils/ ...  because they are adding / to the end of the resource url.

I'm new to rewrite rules.. But how can i update to ignore those requests in my rules.


                           
                      
            
            
          
          
        
        
          
          
        
#131793
Aug 05, 2015 12:17
Vote:
 

The regex's in the rules: 

    <match url="(.*[^/])$" /> 

and

    <match url=".*[A-Z].*" 

need to be modified to ignore URL's starting with /episerver and /util.

I'm no regex guru so I am afraid you will have to work that one out for yourself...

David

#131849
Edited, Aug 06, 2015 19:38
Vote:
 

yes thanks... 

i have now this.. and that works good. Only can someone help how i can chain these two.. I'm no expert in rewrite rules.

<rule name="Add trailing slash" stopProcessing="true">
          <match url="(.*[^/])$" />
          <conditions>            
            <add input="{URL}" pattern="^/episerver" ignoreCase="true" negate="true" />
            <add input="{URL}" pattern="^/util" ignoreCase="true" negate="true" />
            <add input="{URL}" pattern="\.+" negate="true" />
          </conditions>
          <action type="Redirect" redirectType="Permanent" url="{R:1}/" />
        </rule>
        <rule name="Convert to lower case" stopProcessing="true">
          <match url=".*[A-Z].*" ignoreCase="false" />
          <conditions>
            <add input="{URL}" pattern="^/episerver" ignoreCase="true" negate="true" />
            <add input="{URL}" pattern="^/util" ignoreCase="true" negate="true" />
            <add input="{URL}" pattern="\.+" negate="true" />
          </conditions>
          <action type="Redirect" url="{ToLower:{R:0}}" redirectType="Permanent" />
        </rule>
#131855
Aug 07, 2015 8:58
Vote:
 

Hello Vishal

From memory the first matching rule is applied when applying the rule. So they should be chained together as the first rule will be checked then redirect applied and potentialy match the second rule.

However the best way to chain the rules would be to combine into a "Add trailing slash AND Convert to lower case" rule. Some pseduo code like this:

<rule name="Add trailing slash AND Convert to lower case" stopProcessing="true">
    <match url="(.*[A-Z].*)|((.*[^/])$)" ignoreCase="false" />    << Need to write regex to check for check for upper case OR URLs that don't end with "/"
    <conditions>
           <add input="{URL}" pattern="^/episerver" ignoreCase="true" negate="true" />
           <add input="{URL}" pattern="^/util" ignoreCase="true" negate="true" />
           <add input="{URL}" pattern="\.+" negate="true" />
    </conditions>
    <action type="Redirect" url="{ToLower:{R:0}}/" redirectType="Permanent" />
</rule>

David

#131881
Edited, Aug 07, 2015 14:32
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.