IIS从一个子域重定向到另一个子域

时间:2013-08-03 07:19:56

标签: iis redirect url-rewriting web-config subdomain

我需要设置规则,以便将用户从一个子域推送到另一个子域。我需要搬家

  • teststore.domain.edu/admin *
  • devstore.domain.edu/admin *
  • anysubdomain.domain.edu/admin *

  • store.admin.domain.edu/admin

这有效!

但我需要在

下重写任何内容
  • store.admin.domain.edu

  • store.admin.domain.edu/admin

那并没有,除了

之外什么都没有
  • store.admin.domain.edu/media *
  • store.admin.domain.edu/js *
  • store.admin.domain.edu/skin *
  • store.admin.domain.edu/api *
  • store.admin.domain.edu/admin/oauth_authorize *
  • store.admin.domain.edu/index.php/admin *

需要将重定向写入

  • store.admin.domain.edu/admin *

我几乎拥有它,但是store.admin.domain.edu通过下面的规则重写为devstore.domain.edu,因为它没有被捕获。我不能在下面的规则中添加任何内容,它是生成的。

<!-- RULES TO PUSH ADMIN TO SUBDOMAIN -->
<rule name="admin" stopProcessing="true">
  <match url="(.*)"  ignoreCase="true" />
  <conditions logicalGrouping="MatchAll">
    <add input="{HTTP_HOST}" pattern="store.admin.domain.edu" negate="true" />
    <add input="{URL}" pattern="^(.*?)/admin(.*?)" />
  </conditions>
  <action type="Redirect" url="http://store.admin.domain.edu/admin" appendQueryString="false" redirectType="Permanent" />
</rule>
<rule name="admin_rooted" stopProcessing="true">
  <match url="(.*)"  ignoreCase="true" />
  <conditions logicalGrouping="MatchAll">
    <add input="{HTTP_HOST}" pattern="store.admin.domain.edu" />
    <add input="{URL}" pattern="^/(api|oauth_authorize|media|skin|js)" negate="true" />
    <add input="{URL}" pattern="^admin*" negate="true" />
    <add input="{REQUEST_URI}" pattern="^index.php/admin/*" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
  </conditions>
  <action type="Redirect" url="http://store.admin.domain.edu/admin" appendQueryString="false" redirectType="Permanent" />
</rule>
<!-- END OF RULES TO PUSH ADMIN TO SUBDOMAIN -->



<!-- rules that are generated -->
<rule name="default_store">
    <match url="(.*)" ignoreCase="true" />
    <conditions>
      <add input="{SERVER_NAME}" pattern="^devstore\.domain\.edu*" />
    </conditions>
    <serverVariables>
      <set name="HTTP_X_MAGE_RUN_CODE" value="base" replace="true" />
      <set name="HTTP_X_MAGE_RUN_TYPE" value="website" replace="true" />
    </serverVariables>
    <action type="None" />
</rule>
<rule name="general_rewrite">
    <match url="(.*)" />
    <action type="Rewrite" url="index.php" />
    <conditions>
        <add input="{URL}" pattern="^/(media|skin|js)/" ignoreCase="false" negate="true" /> 
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
</rule>

1 个答案:

答案 0 :(得分:1)

我已经改变了你的2条规则,使它们变得更简单:

<rule name="admin" stopProcessing="true">
  <match url="^admin" ignoreCase="true" />
  <conditions logicalGrouping="MatchAll">
    <add input="{HTTP_HOST}" pattern="^store.admin.domain.edu$" negate="true" />
  </conditions>
  <action type="Redirect" url="http://store.admin.domain.edu/admin" appendQueryString="false" redirectType="Permanent" />
</rule>
<rule name="admin_rooted" stopProcessing="true">
  <match url="^(api|oauth_authorize|media|skin|js|admin|index.php/admin/)" ignoreCase="true" negate="true" />
  <conditions logicalGrouping="MatchAll">
    <add input="{HTTP_HOST}" pattern="^store.admin.domain.edu$" />
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
  </conditions>
  <action type="Redirect" url="http://store.admin.domain.edu/admin" appendQueryString="false" redirectType="Permanent" />
</rule>

第一条规则会重定向以admin开头且未指向主机store.admin.domain.eduhttp://store.admin.domain.edu/admin的任何网址。

第二个会重定向任何不以下列事件开头的网址:apioauth_authorizemediaskin或{{1} }或jsadmin指向主机index.php/admin/,而不是store.admin.domain.edu的文件或目录的路径。