August 21, 2005
Dynamic RSS Feeds
August 21, 2005, 11:17 PM | 0 Comments
I was trying to decide how I was going to implement an RSS feed for my site. My original thought is that I would just generate a new XML file every time I posted a new entry to the blog using PHP and creating an XML file much like a text file. (Using the Filesystem functions).
I fired up Google and did a search for ‘PHP Generating RSS XML File.’ After browsing through the first few results I came across this site which has a brief tutorial on how to create a dynamic RSS feed.
Basically, what you do is tell Apache (using either the httpd.conf file or an .htaccess file) to process your XML files as a PHP file.
Anyways, instead of re-stating the entire article, I’ll assume you read it and come back to read about how I used this technique (and made a nifty obvious change) for this site.
The major drawback of using the httpd.conf file is that it’ll force Apache to process all XML files as PHP files, which in most cases would be ok, but could cause problems if you’re not expecting this behavior, or if you forget that you added those changes to the conf file.
Apache regulars will not find the information that follows ground-breaking, but it wasn’t really made obvious in the article, so I’ll point it out here.
The main problem (as I hinted at above) to adding the AddType declaration to Apache’s configuration file is that it will process all XML files as PHP files. Using the .htaccess file is a much better method at accomplishing the same thing, but the difference is, you can place the .htaccess file in the same directory as your dynamic XML files. This will cause Apache to process only those files in the dynamic RSS directory (where you’ll place the .htaccess file) as PHP files.
To illustrate, your file structure would look like this:
/some_xml_file.xml
/xml-rss-dir/.htaccess
/xml-rss-dir/index.xml
root directory (/): some_xml_file.xml - processed normally as XML.
xml-rss directory (/xml-rss-dir/): .htaccess - contains the AddType rule to Tell Apache to process XML files as PHP scripts.
xml-rss directory (/xml-rss-dir/): index.xml - this file will be processed as a PHP file.
For those of you with IIS servers using ASP/ASP.NET, I’m sure that dynamic RSS feeds can be accomplished in the same fashion. I’ll investigate and post an update when I get it all worked out.
Posted in: Reinspire, Web Development
