简体   繁体   中英

Restricting direct access to files using .htaccess

I have video files in a folder. And I want to restrict the users from directly accessing them. I have my .htaccess like this

RewriteEngine on 
RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost [NC] 
RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost.*$ [NC] 
RewriteRule \.(mp4|flv)$ - [F]

IDEA:

This will allow the browser to access my video when requested from page. But it will deny direct access from url.

Actual response:

Its working fine for Chrome. But in all other browsers (firefox, opera, midori) Its giving StreamNotFound error. What is the issue? Any help please.

Try this rule:

RewriteEngine on

RewriteCond %{HTTP_REFERER} !^$ [NC] 
RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost [NC] 
RewriteRule \.(mp4|flv)$ - [NC,F]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM