.htaccess allow file just if string is added at en

2019-09-12 11:47发布

i have some links

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

so all mp4 files can be access only if u add ?token=12345 at end

so without it

 RewriteCond %{QUERY_STRING} !^token=12345
RewriteRule ^.* - [F,L]

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

标签: .htaccess
1条回答
走好不送
2楼-- · 2019-09-12 12:05

What you had should work. Try this:

RewriteEngine on
RewriteCond %{QUERY_STRING} !=token=12345
RewriteRule \.mp4$ - [F,L]

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]

Replacing /video with the path to the video. Make sure it's not .mp4 or you'll get a loop.

Let me know any problems.

查看更多
登录 后发表回答