Reputation: 915
I have a domain name pointed to the root of my hosted account. Within the root directory I have a Web.Config(for url rewriting only) and 2 application starting points namely: /josh and /sudoktion.
My url rewrite rules are built to do this: if a user goes to www.sudoktion.com it goes to /sudoktion, likewise if a user goes to josh.sudoktion.com it goes to /josh. This works perfectly.
<rule name="Rewrite1" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.sudoktion.com$" />
</conditions>
<action type="Rewrite" url="sudoktion/{R:1}" />
</rule>
<rule name="Rewrite9" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^josh.sudoktion.com$" />
</conditions>
<action type="Rewrite" url="josh/{R:1}" />
</rule>
However the issue im having is if a user goes to: sudoktion.com without appending www. to the beginning it will take the users to the root and expose the contents of the root. I tried adding a new rule with the pattern="sudoktion.com$" and rewriting that to sudoktion/ that works however it breaks the styling of josh.sudoktion.com a paths issue.
How can I add a rewrite rule of sudoktion.com/ to sudoktion/ without breaking the rule josh.sukoktion.com to josh/ ?
Upvotes: 0
Views: 215
Reputation: 6138
Add the following extra line to the conditions of the first rule:
<add input="{HTTP_HOST}" pattern="^sudoktion.com$" />
and make it match any of these two rukes. So the entire XML of the rule will be:
<rule name="Rewrite1" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^sudoktion.com$" />
<add input="{HTTP_HOST}" pattern="^www.sudoktion.com$" />
</conditions>
<action type="Rewrite" url="sudoktion/{R:1}" />
</rule>
Upvotes: 1