.htaccess允许文件,即使在末尾添加了字符串 [英] .htaccess allow file just if string is added at end
问题描述
我有一些链接
example.com/1.mp4
example.com/2.mp4
有没有一种方法可以阻止直接访问那些文件,但是允许,只要您添加此
is there a way to block accessing directly to those files but allow just if u add this
example.com/1.mp4?token=12345
example.com/1.mp4?token=12345
因此,只有在您添加?token = 12345 结尾
so all mp4 files can be access only if u add ?token=12345 at end
因此没有它
RewriteCond %{QUERY_STRING} !^token=12345
RewriteRule ^.* - [F,L]
我尝试了此方法,但没有用,所以我希望那些mp4可以在vlc或任何其他播放器上播放,即使?token = 12345出现也可以,否则重定向到任何其他视频
i tried this but is not working, so i want those mp4 to be played on vlc or any other player just if ?token=12345 is presend otherwise redirect to any other video
推荐答案
您应该使用的工具。试试这个:
What you had should work. Try this:
RewriteEngine on
RewriteCond %{QUERY_STRING} !=token=12345
RewriteRule \.mp4$ - [F,L]
在上将禁止返回。 mp4
文件,除非存在 token = 12345
。对于重定向到视频,您可以使用以下方法做到这一点:
That will return forbidden on .mp4
files unless token=12345
is present. As for redirecting to a video, you could do that with:
RewriteEngine on
RewriteCond %{QUERY_STRING} !=token=12345
RewriteRule \.mp4$ /video [R=301,L]
用视频的路径替换 /视频
。确保它不是 .mp4
,否则会出现循环。
Replacing /video
with the path to the video. Make sure it's not .mp4
or you'll get a loop.
让我知道任何问题。
这篇关于.htaccess允许文件,即使在末尾添加了字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!