【问题标题】:IIS rewrite module 301 redirects remove folder adding extra slashIIS 重写模块 301 重定向删除文件夹添加额外的斜杠
【发布时间】:2013-09-18 03:14:03
【问题描述】:

我有这个 IIS 重写规则

<rule name="Redirect rule for aliased Pages">
    <match url="^/pages/(.*)" />
    <action type="Redirect" url="{R:1}" />
</rule>

想法是它应该将http://mydomain.com/pages/about-us/ 重定向到http://mydomain.com/about-us/。根据 IIS 中的测试人员,在这种情况下,R:1 是 about-us/,但重定向总是转到 http://mydomain.com//about-us/(参见双 //)。我尝试从匹配 URL 中删除两个正斜杠并将每个正斜杠单独保留,但似乎没有任何区别。

知道额外的 / 是从哪里来的吗?

【问题讨论】:

    标签: iis redirect url-rewrite-module


    【解决方案1】:

    URL 重写模块在初始斜杠之后开始检查,因此以下将删除第一级文件夹“pages”:

    <rule name="Redirect rule for aliased Pages">
      <match url="^pages/(.*)" />
      <action type="Redirect" url="{R:1}" />
    </rule>
    

    测试:

    正如预期的那样。

    请注意,如果您将重写规则放在单独的文件中,则需要回收应用程序池或重新启动 IIS 以使更改生效。

    另外,规则的顺序也很重要。

    【讨论】:

      猜你喜欢
      • 2015-06-24
      • 1970-01-01
      • 1970-01-01
      • 2013-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-07
      • 1970-01-01
      相关资源
      最近更新 更多