<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <clear />
                <rule name="S3 Hosted Help (# legacy redirect)" stopProcessing="true">
                    <match url="^(.*)/([^/]+)/([^/]+)/(.*)$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{QUERY_STRING}" pattern="fragment=([^&amp;]+)" negate="true" />
                        <add input="{REQUEST_FILENAME}" pattern="#CSHID=([0-9]*)" negate="true" />
                    </conditions>
                    <action type="Redirect" url="http://help.financialforce.com/{R:1}/{R:2}/{R:4}" redirectType="Temporary" />
                </rule>
                <rule name="S3 Hosted Help (%23 legacy redirect)" stopProcessing="true">
                    <match url="^(.*)/([^/]+)/([^/]+)/(.*)(#CSHID=[0-9]*)$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{REQUEST_FILENAME}" pattern="#CSHID=([0-9]*)" />
                    </conditions>
                    <action type="Redirect" url="http://help.financialforce.com/{R:1}/{R:2}/{R:4}#CSHID={C:1}" redirectType="Temporary" />
                </rule>
                <rule name="S3 Hosted Help Redirect (for legacy controller)" enabled="true" stopProcessing="true">
                    <match url="^(.*)/([^/]+)/([^/]+)/(.*)$" />
                    <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
                        <add input="{QUERY_STRING}" pattern="^(fragment=([^&amp;]+))?$" />
                    </conditions>
                    <action type="Redirect" url="http://help.financialforce.com/{R:1}/{R:2}/{R:4}#{C:2}" appendQueryString="false" redirectType="Temporary" />
                </rule>
                <rule name="IIS authed assets" enabled="false" stopProcessing="true">
                    <match url="authed/.*" />
                    <conditions logicalGrouping="MatchAny" trackAllCaptures="true">
                        <add input="{HTTP_COOKIE}" pattern="[;\s]?PHPSESSID=([a-z0-9]+)" negate="true" />
                        <add input="{DOCUMENT_ROOT}\assets\ffdc\_iisauth\session\{C:1}.config" matchType="IsFile" negate="true" />
                    </conditions>
                    <action type="Redirect" url="/Security/login?BackURL={UrlEncode:{REQUEST_URI}}&amp;iis_authed_assets=deny" appendQueryString="false" logRewrittenUrl="true" redirectType="Temporary" />
                </rule>
                <rule name="New help: locale fallback" enabled="false" stopProcessing="true">
                    <match url="^(.*)/([^/]+)/([^/]+)/(.*)$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{R:3}" pattern="^default$" negate="true" />
                    </conditions>
                    <action type="Redirect" url="{R:1}/{R:2}/default/{R:4}" redirectType="Found" />
                </rule>
                <rule name="New help: fragment carrier" enabled="false" stopProcessing="true">
                    <match url="^.*$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{QUERY_STRING}" pattern="^fragment=([^&amp;]+)$" />
                    </conditions>
                    <action type="Redirect" url="{R:0}#{UrlDecode:{C:1}}" appendQueryString="false" redirectType="Found" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
