Can an RSS file be made portable (with relative links or scripting)?

那年仲夏 提交于 2019-12-11 09:42:39

问题


Is it possible to make a static RSS feed file that can be moved from server to server without change? It appears that relative links are not fully supported in RSS, but the latest info I've found is quite old; something javascripty would work in HTML, but not in RSS XML.

Background: I'm working with an HTML publishing project that generates static RSS feed files for some lists of resources. To update, you'd re-publish the static file to the same location. One export option is to save to your filesystem and then transfer to the server manually, but for RSS feeds we're currently requiring the destination URL to be entered on export.


回答1:


In the script that generates your RSS, you could do something like this:

<?php
    // example: $_SERVER['HTTP_HOST'] = 'mysite.com';
    $mysite = 'http://' . $_SERVER['HTTP_HOST'];

    // the page you're linking to
    $thislink = 'mypage.html';

    /* code that generates your RSS */

    // output the link
    echo '<a href="' . $mysite . '/' . $thislink . '">';

    /* more code that generates your RSS */
?>

Output:

<a href="http://mysite.com/mypage.html">


来源:https://stackoverflow.com/questions/5235816/can-an-rss-file-be-made-portable-with-relative-links-or-scripting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!