asp.netiisurl-rewritingweb-configwebmatrix

IIS rewrite URL in asp.net goes to into infinity loop


I just need to create a rule in my web config file to rewrite all URLs to given into rule

ex: url/services/presentations-evenementielles to url/Services/Presentations-Evenementielles

This is all made for SEO purposes to avoid duplicates.

<rule name="ProductionRule2" stopProcessing="true" patternSyntax="ExactMatch" >
                <match url="^/productions/xyz" ignoreCase="true" />
                <action type="Redirect" url="Productions/XYZ" redirectType="Permanent"/>
              </rule>

Above code its gives me infinite loop error.


Solution

  • There was some mistakes with your rule

    1.You were trying to use "^" in an exact match rule. Please set it to regular expression

    2.You are trying to use "/" in match url. The match url part of domain/productions/xyz is productions/xyz instead of /production/xyz.

    3.You are enabling ignore case when you redirect URL to itself.

    So please try to modify the rule like this

    <rule name="ProductionRule2" patternSyntax="ECMAScript" stopProcessing="true">
                    <match url="^productions/xyz" ignoreCase="false" />
                    <action type="Redirect" url="Productions/XYZ" redirectType="Permanent" />
                  </rule>
    

    Update:

    Please modify the rule like this

    <rule name="ProductionRule2" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
                    <match url="^Productions/XYZ" ignoreCase="false" negate="true" />
                    <action type="Redirect" url="Productions/XYZ" redirectType="Permanent" />
                        <conditions>
                            <add input="{ToLower:{URL}}" pattern="/productions/xyz" />
                        </conditions>
                  </rule>
    

    And this is working on my side enter image description here

    Please remember to clean browser cache when you test the rule.And the URL should be prODuctions/Xyz instead of prODuction/Xyz.