nav-left cat-right
cat-right

How to Embed and Display YouTube Videos on a Secure SSL Page

EDIT 08/03/2010: A reader just pointed out that the method outlined in this post will present a warning in in the status bar when using the latest version of FireFox. No popups or dialog messages though – that’s good. And it still works flawlessly in IE and Chrome. Thanks to Jayapal for pointing the warning in FF.

Here is a cool trick to get rid of ssl security warning errors when embedding youtube videos into secure web pages.

This soultion will work if your server is using Apache and has Mod_Rewrite enabled (most Linux web hosting companies do).

First, add this to your .htaccess file:

RewriteEngine on
RewriteBase /
RewriteRule ^youtube/(.*)$ http://www.youtube.com/$1 [L]

Then to actually embed the video using the following format:

  <object width="560" height="340">
    <param name="movie" value="https://www.yourdomain.com/youtube/v/mydjFYoD4WS&hl=en_US&fs=1&rel=0&autoplay=1">
    </param>
    <param name="allowFullScreen" value="true">
    </param>
    <param name="allowscriptaccess" value="always">
    </param>
    <embed src="https://www.yourdomain.com/youtube/v/mydjFYoD4WS&hl=en_US&fs=1&rel=0&autoplay=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"></embed>
  </object>

Notice the urls in the embed code are https://www.yourdomain.com/youtube/….

With the rewrite code in place in your htaccess file, Apache will now see those urls and rewrite them into the actual youtube urls (http://www.youtube.com/….). The result…no more security warnings. :) The secure page loads securely. The youtube video plays without causing any warning problems.

13 Responses to “How to Embed and Display YouTube Videos on a Secure SSL Page”

  1. Hi,
    Excellent idea.
    It saved many hours for me.
    As you have said it seems the firefox latest versions are showing a warning icon in the status bar but… fine. That’s is not a matter at all cause we dont want any dialog boxes of warnings and this code is doing it.

    Thank you.

  2. Doesn’t work for me.

    Firefox 3.6 displays the video, but does not remain encrypted.

    IE7 does not display the video.

    • Adam says:

      Do you have a link to it? Did it work for you in IE8?

      Worked for me in both IE7 and IE8.

      Possibly there is more to it, with server configurations – versions of mod_ssl on the server.

      • The link is temporary and in a secure location… Your solution looks good to me technically. Perhaps there is something about the server set up that is causing it not to work. I may revisit your solution in the future as it does seem elegant, but I’m under pressure to get this video up. So, I’m going with a downloaded .flv solution for now.

        Thanks for your reply.

  3. Tried putting the video on a page and then wrapping the page in an iframe. The SSL didn’t work in either FF or IE.

    I ended up downloading it and streaming .flv

  4. Great says:

    Great post. Do you know some website where is possbile to download youtube movies?

  5. It works, but only with a few alterations:

    RewriteRule ^youtube/(.*)$ http://www.youtube.com/$1 [L]

    became
    RewriteRule ^/youtube/(.*)$ http://www.youtube.com/$1 [L]

  6. mrhaw says:

    In my case I just skip the full url and start with “youtube/v..” Very cool and another reminder how insecure the web is.

    Browsers need a way of dealing with half enctypted sites. Than facebook etc could go for SSL.

  7. Y.G.J says:

    you saved me! thank you very muuuuuuuuuuch

  8. blans says:

    For me it works with FF and https stays but I loose the Blue security tab.

    In Chrome all fine

    In IE 8 it doesn’t show the movie…

    So for me this it not an option (yet). I would be willing to loose the blue tab if it would work cross browser.

  9. J Bruni says:

    Used this with NginX:

    location ~ ^/youtube/(.*)$ {
    rewrite ^ https://www.youtube.com$request_uri;
    }

    Works even with latest Firefox. The trick is to use https also in the YouTube URL.

Leave a Reply