apache.htaccesswebm

htaccess fallback rule for webm video files


I would like to start using webm video files on my wordpress website.

Webm video files show correctly on Chrome and Firefox, but not on Internet Explorer.

So I'm trying to add an htaccess rule to replace webm with an mp4 file with same name when webm is unsupported by browser

But it does not work. Any hint would be greatly appreciated.

 RewriteCond %{HTTP_ACCEPT} !video/webm
 RewriteCond %{DOCUMENT_ROOT}/$1.mp4 -f
 RewriteRule (.+)\.webm$ $1.mp4 [T=video/mp4,E=REQUEST_video]

Solution

  • For those interested I've managed to find a working alternative solution with jQuery:

    function webm_fallback()
    {
        if (is_single()) {
    
            ?>
    <script>
        (function($){
            $(document).ready(function(){
    // detect Internet Explorer
            if((navigator.userAgent.indexOf("MSIE") != -1 ) || (!!document.documentMode == true )){
    // replace 
                $('source').each(function(){
                    var source = $(this).attr('src');
                    $(this).attr('src',source.replace('.webm', '.mp4'));
                    $(this).prop('type','video/mp4');            
    
                });       
            }
        });
    })(jQuery);
        </script>
    <?php
        }
    }
    
    add_action('wp_head', 'webm_fallback');