简体   繁体   English

IIS URL重写问题

[英]IIS URL Rewrite Issue

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. 在根目录中,我有一个Web.Config(仅用于URL重写)和2个应用程序起点,即/ josh和/ 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. 我的URL重写规则就是为此而构建的:如果用户访问www.sudoktion.com,则转到/ sudoktion,同样,如果用户访问josh.sudoktion.com,则转到/ 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. 但是,我遇到的问题是,如果用户转到:sudoktion.com而没有附加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. 我尝试添加带有pattern =“ sudoktion.com $”的新规则,并将其重写为sudoktion /,该规则有效,但是它打破了josh.sudoktion.com路径样式的样式。

How can I add a rewrite rule of sudoktion.com/ to sudoktion/ without breaking the rule josh.sukoktion.com to josh/ ? 如何在不破坏josh.sukoktion.com规则的情况下向sudoktion /添加sudoktion.com/的重写规则?

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: 因此,规则的整个XML将是:

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM