Im currently working on url rewriting an old web application of mine, and Im wondering if its possible to rewrite links in a rss feed.
I currently have this outbound rewrite rule. The problem is that nothing happens if I add link in filterbytags, because the url is not a href attribute as far as i understand.
<rule name="OutboundShowPost" preCondition="ResponseIsXml1">
<match filterByTags="Link" pattern="^(.*/)pages/frontend/forum/showpost\.aspx\?forum=([^=&]+)&(?:amp;)?post=([^=&]+)$" />
<action type="Rewrite" value="{R:1}forum/{R:2}/post/{R:3}" />
</rule>
The xml content i generate in a aspx file looks like this:
<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>
Is it possible to rewrite the url between the link tags, or do I have to generate the link already rewritten? I would like to avoid that as that would fragment the urlrewrite and I prefer to have it all in one place.
If I generate the rss feed link as a href like this it works, but this is against the standard, and even though some rss readers still accept that I would prefer to avoid this as well.
<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>
After reading a blog post regarding a hack adding an attribute to a link using url rewrite, I managed to get it working using some escaping hack to trick the rewrite rule into generating the correct link.
Using the rule:
<rule name="OutboundNewThreadsLink" preCondition="ResponseIsXml1">
<match filterByTags="CustomTags" customTags="XmlTags" pattern="^(.*/)pages/frontend/forum/showpost\.aspx\?forum=([^=&]+)&(?:amp;)?post=([^=&]+)&(?:amp;)?page=([^=&]+)$" />
<action type="Rewrite" value=""/><link>{R:1}forum/{R:2}/post/{R:3}/{R:4}</link><copyright href="" />
</rule>
<customTags>
<tags name="XmlTags">
<tag name="category" attribute="href" />
</tags>
</customTags>
Would make this 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>
Display as this:
<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>
Obviously the category and copyright doesnt contain href attributes, but you could use this with <guid isPermaLink="false">
and <source url="">
, or any of the other tags that contain attribute values, to create a 100% valid rss feed.
I didnt continue down this path though, and instead opted to pre-rewrite the feed links.
This is just to let anyone know that is it indeed possible, however somewhat of a hack since you need to create the rss feed to work with the rewrite, and if the feed is uploaded anywhere where rewrite isnt enabled, this would result in an invalid rss feed.