动态RSS应该使用什么文件扩展名?


What file extension should I use for dynamic RSS

我目前正在开发一个动态RSS提要,它将自动从MySQL数据库中提取文章。代码在

下面
<?php 
//Include the post retreival script
require_once '../phpScripts/rss_db_setup.php';
//Set the content type
header('Content-type: text/xml');
//Set up the RSS feed information
echo '<?xml version="1.0" encoding="ISO-8859-1"?>'.
 '<rss version="2.0">'.
 '<channel>'.
 '<title>Company Name</title>'.
 '<link>http://www.company.ca</link>'.
 '<description></description>'.
 '<category></category>';
//Retreive posts from the database
$rssData = new rssData();
echo $rssData->generateFeed($dbcon);
//Close the feed
echo '</channel></rss>';
?>

我想知道这个文件是否应该保存为。xml或。php?我已经将以下行添加到我的。htaccess文件中,但并不真正理解它是如何工作的

AddType application/x-httpd-php .xml

这样做正确吗?或者我应该使用另一个htaccess函数,如modRewrite,或者使用CRON作业每天生成一个新的。xml ?

RSS不需要扩展名。它不关心url是/feed.php /feed.xml还是/feed/。这和你硬盘上的文件不一样。HTTP发送内容类型头来指定文件的类型。

但是(正式地)它需要正确的内容类型标头。在代码中指定text/xml,正式格式应为application/rss+xml。

如果在服务器的其他地方使用静态xml文件,使用AddType可能会出现问题。PHP会在每个xml文件的开头部分卡住,给出一个很好的错误消息,导致无效的xml。

使用AddType application/x-httpd-php .xml行,Apache将能够提供包含一些PHP代码的XML文件。可以将此文件保存为。xml, PHP代码将被解释为

也许你应该添加一个缓存管理器,以避免在没有新文章时生成相同的提要?