Как применить только одно URL Rewrite-Rule в VB.net - PullRequest
0 голосов
/ 01 ноября 2019

Я написал 3 правила в web.config. То, что я хочу, это когда мое первое правило применяется, тогда остальные правила не оцениваются. Мой код ниже.

Когда Первое правило применяется:

Первое правило

<rule name="Redirect to HTTPS" stopProcessing="true">
  <match url="(.+)\.test\.com" />
  <conditions>
    <add input="{HTTPS}" pattern="off" />
    <add input="{HTTP_HOST}" pattern="(.+)\.test\.com" />
  </conditions>
  <action type="Redirect" url="https://{C:0}/{R:0}" />
</rule>

... затем Другие правила пропускаются и не проверяются:

Другие правила

<rule name="All HTTP to HTTPS+WWW" stopProcessing="true">
  <match url=".*" />
  <conditions trackAllCaptures="true">
    <add input="{SERVER_PORT_SECURE}" pattern="0" />
    <add input="{HTTP_HOST}" pattern="(?:localhost|stage\.|dev\.)" negate="true" />
    <!--here with this 3rd condition we capture the host name without "www." prefix into {C:1} variable to use in redirect action--> 
    <add input="{HTTP_HOST}" pattern="^(?:www\.)?(.+)" />
  </conditions>
  <action type="Redirect" url="https://www.{C:1}/{R:0}" appendQueryString="true" redirectType="Permanent" />
</rule>

<rule name="All HTTPS With No WWW to HTTPS+WWW" stopProcessing="true">
  <match url=".*" />
  <conditions trackAllCaptures="false">
    <add input="{SERVER_PORT_SECURE}" pattern="1" />
    <add input="{HTTP_HOST}" pattern="(?:localhost|stage\.|dev\.)" negate="true" />
    <add input="{HTTP_HOST}" pattern="^www\." negate="true" />
  </conditions>
  <action type="Redirect" url="https://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" />
</rule>
...