Allowing video to be played in <video> element from my website, but not allowing it through direct link

后端 未结 1 1964
自闭症患者
自闭症患者 2020-12-06 19:52

I used the below tricks:

First, I disabled the right click in order to prevent the user from using save as or get link using this HTML5:

相关标签:
1条回答
  • 2020-12-06 20:51

    This is possible.

    Your .htaccess solution is a good idea, to get it to work, your .htaccess needs to be in a sub-directory with the source videos, and nothing else. Update it so that it looks like this:

    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^http://example.com/.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.example.com/.*$ [NC]
    RewriteRule .(mp4|mp3|avi)$ - [F]`
    

    Alternatively this should work too (to completley block access to your video conent)

    RewriteEngine On
    RewriteCond %{REQUEST_URI} \.(mp4|mp3|avi)$ [NC]
    RewriteRule ^.* - [F,L]
    

    It is required to include both codes together:

    RewriteEngine On
    RewriteCond %{REQUEST_URI} \.(mp4|mp3|avi)$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://sample.com/.*$ [NC]
    RewriteRule ^.* - [F,L]
    

    On a side-note, while we're talking about .htaccess, check out this tool for writing and testing your file: http://htaccess.mwl.be/ . It lets you see which conditions will meet which URL patterns and what the outcome will be, much faster than deploying to your server each time you make a change ;)

    0 讨论(0)
提交回复
热议问题