iTunes (Mac/PC) and iOS built-in Podcast app are unable to process indirect download link (+Solution)

Standard

(Updated) Added solution for Nginx

Symptom)

If the audio/video URL of each item contains extension information, there is no problem.
(Example: http://prl85.com/podcast/example.mp3)

However, if the audio/video URL of each item has no information about file extension, then problem occurs. (Especially if you are using download handler instead of directly downloading file)
(Example: http://prl85.com/somehandler?episode=1)

In latter case, built-in Podcast app only can play episodes by streaming, not from downloaded file.
(After downloading episode, you can’t play that episode unless you delete the downloaded file)

Other podcast apps (Downcast, Podcruncher, …) has no problem with this (playing episodes from downloaded files).

Solution)
1. Apple fixes built-in Podcast app
(but…. when? btw, Mac/WIndows iTunes also have same problem)

2. Use direct link (http://prl85.com/example.mp3, instead of http://prl85.com/somehandler?episode=1) for media link
(but, what if it is inevitable to use download handler link?)
(it could be inevitable to use download handler link when you store the audio/video in cloud storage like dropbox, onedrive, google drive, …)

3. If solution 2 is unavailable, use redirection script (in my case, by PHP)
(http://prl85.com/redirect.mp3?episode=1 -> equivalent to http://prl85.com/somehandler?episode=1, downloads episode 1 file)

the extension of handler file should be that of media file (.mp3, .m4a, …), depending on your original media type.
(For solution 3, requires registering .mp3 or .m4a as being handled by PHP handler – recommends .htaccess in Apache case)

Example of redirection script (redirection.mp3)

<?php header('Content-Type: audio/mp3'); header('Location: http://prl85.com/somehandler?episode=1'); ?>


Example of .htaccess (For apache webserver; put this file with same directory of redirection script)

AddHandler application/x-httpd-php .mp3

Example of nginx.conf (For Nginx webserver; might be complex than Apache case because it requires modification of setting file)

server {
­	location /podcast_service/ { # where the redirection script exists
		location ~ .*\.mp3|.*\.m4a$ { # extensions you want to handle
			fastcgi_pass 127.0.0.1:9000;
			fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
			include fastcgi_params;
			fastcgi_read_timeout 180;
		}
	}
}