Search code examples
windowshttp-redirectiisparametersweb-config

IIS 10 Rewrite with Parameters


i am trying to solve a IIS redirect (http + https) with parameters.

Source-URL: subdomain.example.com

Target-URL: https://target.com/com/en/products-z/xxx/yyy/wow-fan.html?utm_source=oldvanity&utm_medium=redirect&utm_campaign=oldvanity

I used the following web.config :

<?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                <clear />
                <rule name="Redirect to HTTPS" enabled="true" patternSyntax="ExactMatch" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{HTTPS}" pattern="(.*)" />
                    </conditions>
                    <action type="Redirect" url="https://target.com/com/en/products-z/xxx/yyy/wow-fan.html?utm_source=oldvanity&utm_medium=redirect&utm_campaign=oldvanity" appendQueryString="false" redirectType="Permanent" />
                </rule>
                </rules>
            </rewrite>
        <httpRedirect enabled="true" destination="https://target.com/com/en/products-z/xxx/yyy/wow-fan.html?utm_source=oldvanity&utm_medium=redirect&utm_campaign=oldvanity" exactDestination="true" childOnly="true" httpResponseStatus="Permanent" />
        </system.webServer>
    </configuration>

With this web.config an access is not possible and a internal Server error occurs.

HTTP/1.1 500 Internal Server Error
Content-Length: 1192
Content-Type: text/html
Server: Microsoft-IIS/10.0

If i do edit the target in web.config to: Target-URL: https://target.com/com/en/products-z/xxx/yyy/wow-fan.html?utm_source=oldvanity

it works fine.

My web.config does not work with the parameters "&utm_medium=redirect&utm_campaign=oldvanity" in the Targetlink.

I tried $Q$A at the end of in the targetlink as well but did not work.

Any help is highly appreciated. Does anybody know how Target with & in it can be redirected correctly?

Thank you very much and best regards Max


Solution

  • thank you again for your help!

    I have now combined our web.config and it works! :D Also HSTS Support has been added

    @Jalpa - you are great thank you very very much for your help! @Lex Ki - thank you as well - how to read out Server errors is an important point i have ignored in Windows/ IIS so far ;)

    <?xml version="1.0" encoding="UTF-8"?>
        <configuration>
            <system.webServer>
                <rewrite>
                    <rules>
                    <clear />
                    <rule name="Redirect to HTTPS" enabled="true" patternSyntax="ExactMatch" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
                            <add input="{HTTPS}" pattern="(.*)" />
                        </conditions>
                        <action type="Redirect" url="https://target.com/com/en/products-z/xxx/yyy/wow-fan.html?utm_source=oldvanity&amp;utm_medium=redirect&amp;utm_campaign=oldvanity" appendQueryString="false" redirectType="Permanent" />
                    </rule>
                    </rules>
                        <outboundRules>
                    <rule name="Add Strict-Transport-Security when HTTPS" enabled="true">
                        <match serverVariable="RESPONSE_Strict_Transport_Security"
                            pattern=".*" />
                        <conditions>
                            <add input="{HTTPS}" pattern="on" ignoreCase="true" />
                        </conditions>
                        <action type="Rewrite" value="max-age=31536000; includeSubDomains; preload" />
                    </rule>
                </outboundRules>
                </rewrite>
            <httpRedirect enabled="true" destination="https://target.com/com/en/products-z/xxx/yyy/wow-fan.html?utm_source=oldvanity&amp;utm_medium=redirect&amp;utm_campaign=oldvanity" exactDestination="true" childOnly="true" httpResponseStatus="Permanent" />
            </system.webServer>
        </configuration>
    

    All the best