0
votes

I have what to me seems like a simple task with IIS URL Rewrite.

I need to redirect based on sub-domains to a main domain with a query string. For example

demo.domain.com needs to be redirected to www.domain.com/?key=demo

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
    <rewrite>
            <rules>
                <rule name="Redirect" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions trackAllCaptures="true">
                        <add input="{HTTP_HOST}" pattern="demo.domain.com" />
                    </conditions>
                    <action type="Redirect" url="www.domain.com/?key=demo" appendQueryString="false" redirectType="Found" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
1
I've gone through those docs countless times now and I am no closer to a solution. Any other more specific suggestions?maouriceg
Fail request tracing is the best way to check the rewrite process, only in this way can you check the steps to find where the problem is.Bruce Zhang

1 Answers

1
votes

What's happen when you digit demo.domain.com ?

Try to change your code like this :

<rules>
    <rule name="Redirect" stopProcessing="true">
        <match url="(.*)" />
        <conditions trackAllCaptures="true">
            <add input="{HTTP_HOST}" pattern="^demo\.example\.com$" />
        </conditions>
        <action type="Redirect" url="http://www.example.com/?key=demo" appendQueryString="false" redirectType="Found" />
    </rule>
</rules>

Look at the changes in line "add input=" and "action type="