【问题标题】:IIS URL Rewrite - Redirect for subfolder to pageIIS URL 重写 - 将子文件夹重定向到页面
【发布时间】:2016-05-03 07:31:10
【问题描述】:

我想根据以下规则重定向我网站上的所有流量

https://www.test.com/abc -> https://www.test.com/test1.aspx?c=abc
https://www.test.com/def -> https://www.test.com/test1.aspx?c=def

子文件夹需要作为查询字符串传递

我已经试过了,但它似乎不起作用。

<rule name="Reditect1" stopProcessing="true">
                    <match url="^(.*)test.com/(.*)" />
                    <conditions>
                        <add input="{R:2}" pattern="^[a-zA-Z0-9_]*$" />
                    </conditions>
                    <action type="Redirect" url="/test1.aspx?c={C:0}" appendQueryString="true" />
                </rule>

【问题讨论】:

    标签: asp.net url-rewriting iis-7 iis-8 url-rewrite-module


    【解决方案1】:

    因此,经过更多的研究和反复试验,我能够弄清楚。这是我现在的设置方式。

     <rule name="Redirect1" stopProcessing="true">
            <match url="^(.*)$" />
                <conditions>
                    <add input="{R:0}" pattern="^(?!\s*$).+$"/>
                    <add input="{R:0}" pattern="^[a-zA-Z0-9_]*$" />
                </conditions>
            <action type="Redirect" url="/test1.aspx?c={C:0}" appendQueryString="true" />
      </rule>
    

    注意
    该规则是在站点级别而不是 IIS 中的服务器级别设置的。因此,模式匹配忽略了域名。

    ^(.*)test.com/(.*) - tried matching a test.com after the actual qualified domain name. So www.test.com/test.com/abc would satisfy the condition and not www.test.com/abc

    说明

    该规则匹配任何传入的 URL - 模式 (.*)

    第一个条件确保符合条件的域名之后的任何内容都至少有一个非空格字符

    第二个条件确保正在解析的部分中没有特殊字符。这是我的要求。

    【讨论】:

      猜你喜欢
      • 2013-10-16
      • 2017-02-13
      • 2023-04-07
      • 1970-01-01
      • 2013-11-08
      • 1970-01-01
      • 2014-02-28
      • 2011-10-01
      • 1970-01-01
      相关资源
      最近更新 更多