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.

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

This solution 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/(.*)$$1 [L]

Then to actually embed the video using the following format:

  <object width="560" height="340">
    <param name="movie" value=""/>
    <param name="allowFullScreen" value="true"/>
    <param name="allowscriptaccess" value="always"/>
    <embed src="" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"/>

Notice the urls in the embed code are….

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


  1. Jayapal Chandran
    August 4, 2010 - 1:13 pm

    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. Sun Powered Productions
    August 12, 2010 - 6:28 pm

    Doesn’t work for me.

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

    IE7 does not display the video.

    • 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.

      • Sun Powered Productions
        August 12, 2010 - 7:02 pm

        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. Sun Powered Productions
    August 12, 2010 - 6:59 pm

    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 post. Do you know some website where is possbile to download youtube movies?

  5. Sellaband dev team
    September 20, 2010 - 4:48 am

    It works, but only with a few alterations:

    RewriteRule ^youtube/(.*)$$1 [L]

    RewriteRule ^/youtube/(.*)$$1 [L]

  6. 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. you saved me! thank you very muuuuuuuuuuch

  8. 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.

    • Can you send me a link to your implementation of it? I’m curious to try it out. For me, mine is working in IE8 just fine. You can send link here. Thanks.

  9. Used this with NginX:

    location ~ ^/youtube/(.*)$ {
    rewrite ^$request_uri;

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

  10. Probably so. 🙂

Leave a Reply