Sunday, June 9, 2013

IIS URL Rewrite non-www site to www

Use the IIS URL Rewrite module to route a site without "www" prefix to your standard "www" site.  Below is the web.config section to do this.
<system.webserver>
   <rewrite>
      <rules>
         <rule name="Redirect to WWW" stopprocessing="true">
            <match url="(.*)">
            <conditions>
               <add input="{HTTP_HOST}" negate="true" pattern="^www\.([.a-zA-Z0-9]+)$">
               </add>
            </conditions>
            <action appendquerystring="true" type="Redirect" url="http://www.{HTTP_HOST}/{R:0}">
         </action></match></rule>
      </rules>
   </rewrite>
</system.webserver>

No comments:

Can't RDP? How to enable / disable virtual machine firewall for Azure VM

Oh no!  I accidentally blocked the RDP port on an Azure virtual machine which resulted in not being able to log into the VM anymore.  I did ...