允许在< video>中播放视频来自我网站的元素,但不允许通过直接链接 [英] Allowing video to be played in <video> element from my website, but not allowing it through direct link

查看:119
本文介绍了允许在< video>中播放视频来自我网站的元素,但不允许通过直接链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了以下技巧:

首先,我禁用了右键单击以防止用户使用另存为使用此HTML5获取链接

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

<body oncontextmenu="return false;">
</body>

第二:我使用 controlsList =nodownload但问题仅适用于Chrome 58+,因为这个,稍后我可以考虑关税控制如这里

Second: I used the controlsList="nodownload" but the problem it works fine ONLY in Chrome 58+ as per this, later on I may consider customs control as shown here

<video width="512" height="380" controls controlsList="nodownload"
       poster="https://archive.org/download/WebmVp8Vorbis/webmvp8.gif" >
      <source src="videos/289522.mp4" type="video/mp4">
      <source src="videos/289522.ogv" type="video/ogg">
      <source src="videos/289522.webm" type="video/webm">
      Your browser doesn't support HTML5 video tag.
</video>

我仍然需要阻止用户下载它,以防他通过其他方式获得链接,我发现了一些关于使用 .htaccess 的讨论,所以我在 videos 文件夹中创建了一个,并尝试了这个:

I still need to prevent the user from downloading it in case he got the link by other means, I found some talks about using .htaccess, so I created one inside the videos folder, and tried this:

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

并用作替代方式,这个:

and used as an alternate way, this:

<Files "reminder.php">
        Order Deny,Allow
        Deny from all
        Allow from http://my.domain.com/
        Allow from http://my.domain.com/
</Files>

但是发生的事情是视频已被完全阻止,即使是从我的网站本身,我开始得到这个错误:

But what happened is video had been blocked completely, even from my website itself, and I started getting this error:


获取 http://my.domain.com/videos/289522.mp4 500(内部服务器错误)

GET http://my.domain.com/videos/289522.mp4 500 (Internal Server Error)


推荐答案

这是可能的。



你的.htaccess解决方案是一个好主意,为了让它工作,你的 .htaccess 需要位于包含源视频的子目录中,而不是其他任何内容。更新它,看起来像这样:

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]






在旁注上,我们谈的是 .htaccess ,查看此工具以编写和测试您的文件: http://htaccess.mwl.be/ 。它可以让您了解哪些条件将满足哪些URL模式以及结果将会比每次更改时部署到服务器的速度快得多;)


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 ;)

这篇关于允许在&lt; video&gt;中播放视频来自我网站的元素,但不允许通过直接链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆