IIS Rewrite Rule To Force www Sub Domains
Most sites I setup in IIS require a www subdomain as the main entry point to the site while also allowing the non-www version to also work.
Since some sites have multiple domains pointing to them the rewrite rule had to be generic enough that it would handle whatever bindings were setup for it.
If your domain isn’t in the format of example.com
you’ll need to adjust the regex pattern a bit.
You’ll also need IIS 7 or newer and the URL Rewrite module installed to use this.
<?xml version="1.0" encoding="utf-8"?><configuration> <system.webServer> <rewrite> <rules> <rule name="Force non-www to www" stopProcessing="true"> <match url=".*" /> <conditions> <add input="{HTTP_HOST}" pattern="^[^\.]+\.[^\.]+$" /> </conditions> <action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" /> </rule> </rules> </rewrite> </system.webServer></configuration>