1

我目前有一个 PHP 脚本,它在运行时输出一个 XML 文件(但是作为 feed.php 而不是 feed.xml)我被告知将其添加到我的 .htaccess 中,它应该修复它:

AddType application/x-httpd-php .xml

但是由于某种原因,这不起作用。

理想情况下,我希望脚本执行的操作是在运行时生成一个 feed.xml 文件及其内容的输出,而不仅仅是在 php 页面上输出内容。

这是我的代码:

<?PHP
 include("../config.php");
 #// Timetable Clearup Variabls
$yesterday = strtotime('yesterday');
$yesterdow = date('l',$yesterday);
$order = "SELECT * FROM timetable WHERE day = '$yesterdow' ORDER BY time";
$result = mysql_query($order);
$yesterdayd = date('F jS, Y', time()-86400);

    //SET XML HEADER
    header('Content-type: text/xml');

    //CONSTRUCT RSS FEED HEADERS
    $output = '<rss version="2.0">';
    $output .= '<channel>';
    $output .= "<title>Timetable - {$yesterdayd} </title>";
    $output .= '<description>Timetable.</description>';
    $output .= '<link>http://site.com/</link>';
 ###   $output .= '<copyright>Your copyright details</copyright>';
 while ($row = mysql_fetch_array($result)) {
    //BODY OF RSS FEED
   $output .= '<item>';
     $output .= "<description><td>" . htmlspecialchars($row['username']) . "</td><td>" . htmlspecialchars($row['time']) . "</td></description>";
   $output .= '</item> ';
 }
    //CLOSE RSS FEED
   $output .= '</channel>';
   $output .= '</rss>';

    //SEND COMPLETE RSS FEED TO BROWSER
    echo($output);

?>
4

1 回答 1

3

我建议不要在 .htaccess 中添加 .xml 以使用 PHP 编译器进行处理。而是使用mod_rewrite将请求重定向到 .xml 文件到 php 脚本。

例如:

RewriteEngine On
RewriteRule ^(.*)\.xml$ /rss_feed.php [L,QSA]
于 2012-04-11T20:56:32.637 回答