【问题标题】:is it possible to url rewrite a rss xml feed using iis urlrewrite2?是否可以使用 iis urlrewrite2 重写 rss xml 提要?
【发布时间】:2020-07-11 18:09:57
【问题描述】:

我目前正在重写我的一个旧 Web 应用程序的 url,我想知道是否可以重写 rss 提要中的链接。

我目前有这个出站重写规则。问题是,如果我在 filterbytags 中添加链接,则不会发生任何事情,因为据我所知,url 不是 href 属性。

<rule name="OutboundShowPost" preCondition="ResponseIsXml1">
   <match filterByTags="Link" pattern="^(.*/)pages/frontend/forum/showpost\.aspx\?forum=([^=&amp;]+)&amp;(?:amp;)?post=([^=&amp;]+)$" />
   <action type="Rewrite" value="{R:1}forum/{R:2}/post/{R:3}" />
</rule>

我在 aspx 文件中生成的 xml 内容如下所示:

<rss version="2.0">
   <channel>
      <title>test title</title>
      <link>https://example.com</link>
      <description>test description</description>
      <ttl>5</ttl>
      <item>
         <title>test title</title>
         <description>test description</description>
         <link>https://example.com/pages/frontend/forum/showpost.aspx?forum=other&post=&page=1#msg-17</link>
         <pubDate>Tue, 26 May 2020 13:41:18 GMT</pubDate>
      </item>
   </channel>
</rss>

是否可以重写链接标签之间的 url,或者我必须生成已经重写的链接?我想避免这种情况,因为这会使 urlrewrite 碎片化,我更喜欢将它全部放在一个地方。

如果我将 rss 提要链接生成为这样的 href,它可以工作,但这是违反标准的,尽管一些 rss 读者仍然接受我也希望避免这种情况。

<rss version="2.0">
   <channel>
      <title>test title</title>
      <link>https://example.com</link>
      <description>test description</description>
      <ttl>5</ttl>
      <item>
         <title>test title</title>
         <description>test description</description>
         <link href="https://example.com/pages/frontend/forum/showpost.aspx?forum=other&post=&page=1#msg-17"  />
         <pubDate>Tue, 26 May 2020 13:41:18 GMT</pubDate>
      </item>
   </channel>
</rss>

【问题讨论】:

  • "我必须生成已经重写的链接吗?"是的,就像任何其他典型的 Web 应用程序(WordPress 等等)一样。
  • URL 重写仅支持重写 html 标签中的特定属性。 IIS 不支持在 和 之间重写内容。所以你必须找到另一种方法来实现这一点。

标签: iis rss url-rewrite-module web-application-project


【解决方案1】:

在阅读了一篇关于使用 url rewrite 向链接添加属性的 hack 的博客文章后,我设法使用一些转义 hack 来欺骗重写规则生成正确的链接。

使用规则:

<rule name="OutboundNewThreadsLink" preCondition="ResponseIsXml1">
   <match filterByTags="CustomTags" customTags="XmlTags" pattern="^(.*/)pages/frontend/forum/showpost\.aspx\?forum=([^=&amp;]+)&amp;(?:amp;)?post=([^=&amp;]+)&amp;(?:amp;)?page=([^=&amp;]+)$" />
   <action type="Rewrite" value="&quot;/&gt;&lt;link&gt;{R:1}forum/{R:2}/post/{R:3}/{R:4}&lt;/link&gt;&lt;copyright href=&quot;" />
</rule>

<customTags>
    <tags name="XmlTags">
       <tag name="category" attribute="href" />
    </tags>
</customTags>

会制作这个 rss xml:

<rss version="2.0">
   <channel>
      <title>test</title>
      <link>https://localhost:44347</link>
      <description>test</description>
      <ttl>5</ttl>
      <item>
         <title>test</title>
         <description>test</description>
         <category href="https://localhost:44347/pages/frontend/forum/showpost.aspx?forum=andet&post=17-traade-forsvinder"/>
         <pubDate>Tue, 26 May 2020 13:41:18 GMT</pubDate>
   </item>
</channel>
</rss>

显示如下:

<rss version="2.0">
   <channel>
      <title>test</title>
      <link>https://localhost:44347</link>
      <description>test</description>
      <ttl>5</ttl>
      <item>
         <title>test</title>
         <description>test</description>
         <category href=""/>
         <link>https://localhost:44347/forum/andet/post/17-traade-forsvinder</link>
         <copyright href=""/>
         <pubDate>Tue, 26 May 2020 13:41:18 GMT</pubDate>
      </item>
   </channel>
</rss>

显然类别和版权不包含 href 属性,但您可以将其与 &lt;guid isPermaLink="false"&gt;&lt;source url=""&gt; 或任何其他包含属性值的标签一起使用,以创建 100% 有效的 rss 提要。

我并没有继续走这条路,而是选择预先重写提要链接。

这只是为了让任何人知道这确实是可能的,但是有点像黑客,因为您需要创建 rss 提要以使用重写,并且如果提要上传到任何未启用重写的地方,这将导致在一个无效的 RSS 源中。

【讨论】:

    猜你喜欢
    • 2017-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-16
    • 2015-05-10
    • 2013-01-23
    • 2011-01-23
    • 2012-11-08
    相关资源
    最近更新 更多