How can I run a PHP script under a different file extension?

Posted October 8, 2014 20.1k views


First of all, the basics: running latest Ubuntu images with Serverpilot managing the server install.

I created a basic stats script (in the form of download.php?show=XX) for our radio station podcasts and everything works fine, except when trying to listen in iTunes. I checked, and here’s what Apple has to say about the matter:

The URL preceding GET-style form values (before the first “?”) must end in a media file extension (such as .mp3).


How would I change my server config so that I could run my PHP script under an mp3 extension?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers

If this is a one-off exception just for load.php, you can use a rewrite: Add this to your .htaccess file:

RewriteEngine On
RewriteRule /load.mp3 /load.php

If you want all .mp3 files to be parsed as php, add the following line to .htaccess:

AddType application/x-httpd-php .mp3
  • Sweet, I actually didn’t think a rewrite would do it, so that’ll definitely be on the test table! (And I’m nothing your second option somewhere, although, I only need that single case, so that’ll be rewrite!)


    Here is ther .htaccess code I use. It works perfectly fine, the rewrite rule does the trick for iTunes.

    Options +FollowSymlinks
    RewriteEngine On
    RewriteBase /
    RewriteRule ^(.+).mp3$ /$1.php [NC,L]

You can configure Apache to use different extensions for php either through a configuration change or an .htaccess file. This page in the php manual should be what you are looking for: