WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Multisite URL rewrite prevents iphone (all iOS?) from playing video (4 posts)

  1. jimisdon
    Member
    Posted 1 year ago #

    Even asking about this is probably an exercise in futility... but here we go.

    I host multiple WP sites through one install as WP Multisite. When I try to serve HTML5 video, my computer's browsers see the video and play it just fine, but my iphone will not. After pulling out nearly all of my hair I tried something crazy: I directed my iPhone to the actual (not re-written) version of the URL for the file and BOOM. It played no problem.

    So serving it up like this kills the video on my phone but not my computer:
    http://mapped_domain.parent_domain.com/files/2011/10/video.mp4

    But like this plays it without fail:
    http://parent_domain.com/wp-content/blogs.dir/4/files/2011/10/video.mp4

    I'll never be able to get my users to put in the full URL path when they want to link uploaded movies. Not nearly user-friendly enough for them. And it annoys the heck out of me too.

    Is there a way to fix this? Is anyone else having this problem?

  2. sontru
    Member
    Posted 1 year ago #

    Write a plugin to rewrite a shortcode [video.mp4] to http://parent_domain.com/wp-content/blogs.dir/4/files/2011/10/video.mp4 ?

    Or better still find a plugin that does this or deals with the problem.

    I believe the blogs.dir structure for uploaded media has been done away with in 3.5. This might solve your problem, though a new install is needed - an upgrade to 3.5 will keep the blogs.dir structure.

  3. You can wrangle an older install to get rid of MS files: http://halfelf.org/2012/dumping-ms-files/

    Though I didn't have a problem with that particular issue before.

  4. jimisdon
    Member
    Posted 1 year ago #

    Thanks for the ideas, folks. I went ahead and wrote a plugin. It's not as hard coded as I feared it would have to be, thanks to wp_upload_dir(). That function reveals the Unix path to the directory, which can be incorporated into a URL for the videos.

    The plugin solution was far less work than it would have been to get rid of ms-files (I assume). And it probably would have created more problems than it solved. Especially since it really only affected video files and everything else still worked fine on all devices.

    I have been toying with the idea of writing my own HTML5 video plugin for a while, and your suggestion, sontru, was the tipping point. I was actually going to write a shortcode, but I am glad you advised that a plugin would be better. Forced me to build it in a much less error prone way. I figured I'd just incorporate the solution to the URL thing in with it.

    The plugin I wrote sees a regular link to a video, attempts to find all videos with the same name, but different extensions, ranks them (if they even exist) in order for HTML5 video with fallbacks, and writes out the real (un-rewritten) URLs inside proper <video> tags.

    So the plugin is uses two ways to get the better URL. One, as I said was less hard coded:

    $basedir = wp_upload_dir();
    $basedir = $basedir['basedir'];
    $date_folder = NULL;
    preg_match('#/[0-9]{4}/[0-1]{1}[0-9]{1}#', $url_to_original_file, $date_folder);
    $path_to_file = $basedir . $date_folder[0] . '/' . basename($url_to_original_file);

    You basically get the path to "uploads" in lines 1 and 2, get the year and month folders in lines 3 and 4, then put it together along with the filename in 5. From there, you could do a find and replace on the original URL versus the Unix path to get the un-rewritten URL.

    The other way that I also used is slightly less work, but would be a bit more likely to break with future releases... I assume.

    $site_number = $current_blog->blog_id;
    $new_path_insert = "/wp-content/blogs.dir/$site_number/files/";
    $new_url = str_replace('/files/', $new_path_insert, $original_url_to_file);

    In that one, $current_blog is a global set by WordPress. I'll probably ditch the second version and duplicate the first version, ultimately. But I thought since you both took the time to help, you might like to see both ways I got it working.

    Thanks again for the suggestions.

Topic Closed

This topic has been closed to new replies.

About this Topic