.htaccess - If the mp4 video was not found, throw the flv video -
i own video sharing website users upload videos it.
usually videos converted mp4 file , streamed. however, many times due server failures, video gets converted flv files. flv , mp4 files stored within same location under same name.
the player calls 1 video file source:
http://server.mysite.com/location/user/id/file.mp4
i want server throw same link flv file instead of mp4 (if mp4 file not found), in case if mp4 video not found server throw:
http://server.mysite.com/location/user/id/file.flv
how achieve using htaccess?
custom 404 page
how dropping custom 404 error page looks whether alternative file exists , redirects there.
mod_rewrite
second option involves mod_rewrite (untested pseudo-code):
in /etc/httpd/conf/httpd.conf (or wherever httpd.conf lives in distro) enable rewriteengine (you can per vhost if wish so):
rewriteengine on
also don't forget set allowoverrides directory:
<directory /foo/bar> allowoverrides fileinfo </directory>
then in .htaccess do:
rewritebase /foo/bar rewritecond %{script_filename} !-f rewriterule ^(.*).mp4 $1.flv [r=301]
note if apply rewriterules in .htaccess have to setup rewritebase otherwise you'll seeing weird redirects. if set httpd.conf - can still not required.
as option [r=301]
replaced [p], means software think it's getting .mp4 file whereas in fact payload .flv file
see mod_rewrite docs more info