【问题标题】:<httpRedirect/> - match URL containing string<httpRedirect/> - 匹配包含字符串的 URL
【发布时间】:2019-05-12 11:16:26
【问题描述】:

我想将每个包含特定字符串的 URL 重定向到 https://example.com/。我正在使用带有HTTP Redirect installed 的IIS,并且我已在我的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

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

【问题讨论】:

    标签: iis web-config http-redirect


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2019-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-06
      • 2015-11-08
      • 2013-01-09
      • 2022-11-19
      • 2020-12-25
      相关资源
      最近更新 更多