I’m doing url rewriting (Wildcards) for a sigle web site based on
this blog post. This is what I tried:
<rewrite>
<rules>
<rule name="Redirect example.com to www" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_HOST}" pattern="example.com" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:0}" />
</rule>
</rules>
</rewrite>
These codes works perfect and we can add them manually to web.config of web site or use url rewrite in IIS.
My problem is I have many web sites (domains and subdomains – net , com , org) installed on my IIS and I have to do a repeated job for all of them!
Is it possible to use another way for redirecting non www to www (site level or application level) for all web sites? If application level is possible which configuration files should I change? Would you please show us the correct wildcards or regular expressions?
You may edit your
applicationHost.config(int the%systemroot%\System32\inetsrv\configdirectory) so that it includes common url rewriting rules for your IIS installation; the following two rules (one for HTTP, the other for HTTPS requests, if needed) do exactly what you are after:That being said, I think it is not possible to restrict a given set of rules to a specific application pool, however.