<httpredirect>-包含字符串的匹配URL

时间:2018-12-11 12:49:54

标签: iis web-config http-redirect

我想将每个包含特定字符串的URL重定向到https://example.com/。我将IIS与HTTP Redirect installed一起使用,并且已将规则添加到Web.config中。

 <httpRedirect enabled="true" exactDestination="true" httpResponseStatus="Found">
    <add wildcard="*" destination="https://example.com/" />
 </httpRedirect>

问题是wildcard="*"有效,但是wildcard="*foo*"不会重定向包含foo的URL,例如https://localhost/?foo=true

如何使它适用于“ *”以外的通配符?

1 个答案:

答案 0 :(得分:0)

我设法做到了https://serverfault.com/questions/386573/how-to-redirect-an-specific-url-with-specific-variables-in-iis

它使用UrlRewrite模块而不是HttpRedirect。

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="MyRule" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^folder/Default.aspx$" />
          <action 
              type="Redirect" 
              url="folder/Default.aspx?&amp;variable1=ffff&amp;variable2=gggg" 
              appendQueryString="false" 
              redirectType="Found" /> 

          <conditions logicalGrouping="MatchAny">
            <add input="{QUERY_STRING}" 
                 pattern="^&amp;variable1=eeee&amp;variable2=aaa$" />

            <add input="{QUERY_STRING}" 
                 pattern="^variable1=eeee&amp;variable2=aaa$" />
          </conditions>
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>