<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Rexxars.com &#187; Apache</title>
	<atom:link href="http://rexxars.com/tag/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://rexxars.com</link>
	<description>A developers perspective on PHP, Android, MooTools and other awesomeness.</description>
	<lastBuildDate>Fri, 23 Jul 2010 13:47:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Forcing files to be interpreted as PHP with Apache</title>
		<link>http://rexxars.com/apache/forcing-files-to-be-interpreted-as-php-with-apache/</link>
		<comments>http://rexxars.com/apache/forcing-files-to-be-interpreted-as-php-with-apache/#comments</comments>
		<pubDate>Sat, 20 Jun 2009 15:25:57 +0000</pubDate>
		<dc:creator>Rexxars</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://rexxars.com/?p=44</guid>
		<description><![CDATA[I&#8217;ve been writing a couple of web services lately which returns XML data. If I&#8217;m on a deadline and just have to get it up and running, I usually don&#8217;t care for small details, but a hobby project is another matter. When I have the time, I like to sit and tweak the code to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been writing a couple of web services lately which returns XML data. If I&#8217;m on a deadline and just have to get it up and running, I usually don&#8217;t care for small details, but a hobby project is another matter. When I have the time, I like to sit and tweak the code to get the response looking as clean as possible, giving meaningful error messages, logging errors to files etc.</p>
<p>Let&#8217;s say I&#8217;m writing an application that retrieves a list of notes from a web service. The URL for retrieving the XML data would most often look something like:</p>
<pre style="padding-left: 30px;">http://whatever.webservice.com/feeds/latest.php?since=timestamp</pre>
<p>Which is fine, except one little aspect: it doesn&#8217;t tell me if I am getting data back as XML, JSON, CSV or in some other format. I would much rather prefer to have this specified in the URL. Examples of good, clean URLs would be any of the following:</p>
<pre style="padding-left: 30px;">http://whatever.webservice.com/feeds/<span style="color: #ff0000;">xml</span>/latest.php?since=timestamp
http://whatever.webservice.com/feeds/latest.php?<span style="color: #ff0000;">format=xml</span>&amp;since=timestamp
http://whatever.webservice.com/feeds/latest<span style="color: #ff0000;">.xml</span>?since=timestamp
</pre>
<p>I personally think the last one is the prettiest. There are reasons why the two first might be &#8220;better&#8221; from a code and performance perspective though:</p>
<ul>
<li>The subdirectory method could handle outputting of the data in that format and only that format, not needing any if-checks.</li>
<li>The query parameter method could handle a lot of different formats in the same file, and would simply call the correct function to retrieve the data in the correct format.</li>
</ul>
<p>The last one was what I went for in the end. The problem with that is making Apache understand that this &#8220;XML&#8221; file is really a PHP file. I solved this easily with this simple  .htaccess file, which forces every XML file within the directory you place it in to be run through PHP:</p>
<pre style="padding-left: 30px;">&lt;Files *.xml&gt;
ForceType application/x-httpd-php
&lt;/Files&gt;
</pre>
<p>Sending the correct headers is also a bonus:</p>
<pre style="padding-left: 30px;">&lt;?php
header('Content-Type: text/xml; charset=utf-8');
</pre>
<p>Worth the effort? You tell me <img src='http://rexxars.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://rexxars.com/apache/forcing-files-to-be-interpreted-as-php-with-apache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
