繁体   English   中英

URL重写规则(iis):仅重定向www.example.com和www.example.com/default.aspx

[英]URL rewrite rule (iis): redirect ONLY www.example.com and www.example.com/default.aspx

我正在尝试进行重写以仅重定向以下页面:

www.example.com/

www.example.com/default.aspx

我想让其他所有请求通过。 我知道我已经很近了,但是我似乎无法完美。 在此先感谢您提供的所有帮助!

这是我到目前为止的内容:

<rewrite>
   <rules>

    <rule name="Base Redirect" stopProcessing="true">
      <match url="" />
         <conditions>
          <add input="{HTTP_HOST}" pattern="www.example.com" ignoreCase="true" negate="false" />
      </conditions>
      <action type="Redirect" redirectType="Permanent"  url="shop.example.com" appendQueryString="true" />
    </rule>

    <rule name="Default.aspx Redirect" stopProcessing="true">
      <match url="default.aspx" />
         <conditions>
          <add input="{HTTP_HOST}" pattern="www.example.com" ignoreCase="true" negate="false" />
      </conditions>
      <action type="Redirect" redirectType="Permanent"  url="shop.example.com" appendQueryString="true" />
    </rule>

  </rules>
</rewrite>

问题是它正在发送包含default.aspx的任何内容(/pages/default.aspx等),我们只希望重定向根目录default.aspx之外的任何内容。

费利克斯

尝试以下操作(基本上添加“ ^”字符以告诉正则表达式仅在开始时才匹配:

<rule name="Base Redirect" patternSyntax="ECMAScript" stopProcessing="true">
  <match url="^$" />
  <conditions>
                <add input="{HTTP_HOST}" pattern="www.example.com" />
  </conditions>
  <action type="Redirect" url="http://shop.example.com/" appendQueryString="true" redirectType="Permanent" />
</rule>

<rule name="Default.aspx Redirect" stopProcessing="true">
  <match url="^default.aspx" />
  <conditions>
                <add input="{HTTP_HOST}" pattern="www.example.com" />
  </conditions>
  <action type="Redirect" url="http://shop.example.com" appendQueryString="true" redirectType="Permanent" />
</rule>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM