0

Inbound IIS7 Url Rewrite Rule not working

Below is the URL Rewrite rule I've defined.

    <rewrite>
        <rules>
            <rule name="Redirect domain.co.uk to www.domain.co.uk" enabled="true" stopProcessing="true">
                <match url="^domain\.co\.uk(.*)" />
                <action type="Redirect" url="http://www.domain.co.uk{R:1}" />
            </rule>
        </rules>
    </rewrite>

When I go to domain.co.uk it's not redirecting to www.domain.co.uk. Am I doing something wrong?

dnoxs
  • 121
  • 1
  • 3
  • Have you seen [IIS7 URL Rewrite - Add “www” prefix](http://stackoverflow.com/questions/2207059/iis7-url-rewrite-add-www-prefix)? – Andrew Morton May 16 '14 at 20:25

1 Answers1

2

Had to add a condition to get it to work. Like so...

    <rewrite>
        <rules>
            <rule name="Redirect root to www" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTP_HOST}" pattern="^domain\.co\.uk(.*)" />
                </conditions>
                <action type="Redirect" url="http://www.domain.co.uk/{R:1}" />
            </rule>
        </rules>
    </rewrite>

URL Rewrite Tips

dnoxs
  • 121
  • 1
  • 3