locked
match on one occurrence but not another RRS feed

  • Question

  • User1808049267 posted

    Hello, I'm looking to implement a rule that will match when that string is the only item present after the first slash, but not another. Basically, I want the rule to match on this URL

    http://www.example.com/amp

    but not this URL:

    http://www.example.com/test/recipe/amp

    I feel this can be done using something like this as a conditional variable, but this doesn't seem to be working. (essentially using the not operator to ignore anything before amp) :

    <rule name="/amp - 20161205" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
    <add input="{REQUEST_URI}" pattern="(!(.*))/amp$" />
    </conditions>

    <action type="Redirect" url="http://www.example.com/recipes" appendQueryString="false" />
    </rule>

    Monday, December 12, 2016 9:20 PM

All replies

  • User-460007017 posted

    Hi steel811,

    You could use the following rule to achieve your requirement:

                    <rule name="rewrite amp" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions>
                            <add input="{URL}" pattern="^/amp$" />
                        </conditions>
                        <action type="Redirect" url="recipes" appendQueryString="false" redirectType="Temporary" />
                    </rule>

    You could use^/amp$ to pattern the URL /amp. To redirect to the sample domain, you just need to input the subfolder "recipes" in action panel.

    Best Regards,

    Yuk Ding

    Tuesday, December 13, 2016 6:49 AM