对于特定方案或URL,需要一个IIS重写规则

时间:2017-11-27 12:43:51

标签: asp.net iis url-rewrite-module

如果我在浏览器地址栏http://localhost:8800/gb中输入此网址,则地址栏中的网页加载和网址将变为此类http://localhost:8800/gb/default.aspx

但如果我在浏览器地址栏中输入此网址http://localhost:8800/gb/,则会收到错误。

我想要的只是如果我在浏览器地址栏中输入此网址http://localhost:8800/gb/,它应该将我重定向到default.aspx页面。所以如果url以/ gb /或/ us /结尾两个带有两个前斜杠的字符结束,那么应该加载default.aspx。

到目前为止,我已经使用了以下网址重写规则。

<rule name="Always redirect root extensionless path to index.aspx" stopProcessing="true">
      <match url="^$" />
      <action type="Redirect" url="/Default.aspx" appendQueryString="true" logRewrittenUrl="true" />
</rule>

<rule name="Rewrite rule for Redirecting countries" stopProcessing="true">
    <match url=".*.aspx" />
    <conditions trackAllCaptures="true">
      <add input="{REQUEST_URI}" pattern="[a-z]{2}/(.*)" />
    </conditions>
    <action type="Rewrite" url="/{tolower:{C:1}}" appendQueryString="false" logRewrittenUrl="true" />
</rule>

所以请指导我另外一条规则,该规则可以处理此网址http://localhost:8800/gb/并重定向到网站根目录的default.aspx。

感谢

1 个答案:

答案 0 :(得分:0)

此规则适用于我的方案。

当网址为http://localhost:53741/gb/时,则以下规则会重定向到此网址http://localhost:53741/gb/default.aspx

<rule name="redirect two character to default" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
          <add input="{URL}" pattern="^/[a-z]{2}(/)?$" />
      </conditions>
      <action type="Redirect" url="default.aspx" appendQueryString="false" />
</rule>
相关问题