locked
Web.Config - Redirect from non-www to www. but ignore sub-domains RRS feed

  • Question

  • User-1883366772 posted

    Hi all,

    On most sites I use the below code to redirect the non-www version of the domain name to the www. version of it.

    In the case of one site, they have many sub-domains so I need my code to be more specific and only redirect in the case of there being no www. on the domain and to leave any other sub-domains intact.

    so,

    mydomain.co.uk (redirects to) www.mydomain.co.uk

    admin.mydomain.co.uk (no redirect)

    Here's my current global redirect code:

     <rewrite>
         <rules>
            <clear />
            <rule name="WWW Rewrite" enabled="false">
              <match url="(.*)" />
              <conditions>
                <add input="{HTTP_HOST}" negate="true" pattern="^www\." />
              </conditions>
              <action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" />
            </rule>
        </rules>
    </rewrite>



    Friday, August 2, 2013 8:39 AM

Answers

All replies