【问题标题】:Issue redirecting with IIS url rewriting使用 IIS url 重写重定向问题
【发布时间】:2016-06-06 11:45:04
【问题描述】:

我有一个 Asp.Net 网站,它的子目录中也有一个 WordPress 博客。我在尝试创建的重定向规则之一遇到问题。

我在 web.config 中有这个规则:

    <rule name="Remove trailing slash">
      <match url="^(.*(?!/blog/).*)$" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
      </conditions>
      <action type="Redirect" redirectType="Permanent" url="{R:1}" />
    </rule>

它试图做的是,从 URL 中没有博客目录的每个页面中删除尾部斜杠。

它适用于大多数部分。

网站上的任何页面都可以使用:

http://www.mysite/terms

博客主页有效:

http://www.mysite/blog

什么不起作用:

http://www.mysite/blog/my-latest-post

由于某种原因,页面没有正确重定向(或转圈)。

关于如何纠正此问题的任何想法?

【问题讨论】:

    标签: asp.net wordpress iis url-rewriting


    【解决方案1】:

    我会尝试类似的东西

    <rule name="Remove trailing slash">
      <match url="^(.*)/$" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{HTTP_HOST}" pattern"^.*/blog/.*$" negate="true" />
      </conditions>
      <action type="Redirect" redirectType="Permanent" url="{R:1}" />
    </rule>
    

    【讨论】:

    • 我必须对原始语法进行更改才能让它为我工作。原始语法使用服务器变量 [HTTP_HOST],但是博客附加到站点并且是它自己的实体,因此我需要使用 [PATH_INFO],因为“博客”不是主机名的一部分。
    猜你喜欢
    • 2019-02-11
    • 1970-01-01
    • 2012-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-10
    • 2014-10-23
    相关资源
    最近更新 更多