How to configure htaccess to allow PHP files to accessed with XML extension
So supposing you've got a PHP file generating XML (as per my old tutorial on generating an RSS feed using PHP), what happens if you need that file to be linked as XML? This brief tutorial will explain how.
Google Webmaster Tools specifically requests that sitemaps are added only with the .xml extension, in the same way Feedburner require RSS feeds to be linked as XML too. Irrespective of whether you've set the headers for XML, you'll need to perform some .htaccess wizardry to get things working correctly.
Setting .htaccess to allow PHP to be accessed with .xml extension
Firstly you'll need to create a .htaccess file (Google it if you're unsure what one is). The contents of the file should be as per below:
The above code turns on the rewrite-engine which allows you to perform URL-rewriting. The second line is a very broad statement, allowing any file with a .php extension to be accessed as the same filename with a .xml extension. Of course it'd make sense to tie this down to the specific files you need, but in this example I'm matching anything and everything.
With this you can generate RSS feeds and XML sitemaps using PHP (or whatever programming language you wish) and still have them recognised with the XML extension. Just make sure you've set header to be XML on the script itself.
