Evan Ceasar
Evan Ceasar

Reputation: 13

Fix .htaccess .mp4 hotlink protection for mobile

I made an .htaccess to protect against .mp4 stream hotlinker. So far it work fine on PC and all browser. But when view on mobile the video won't load. To see if it's the .htaccess that cause the issue I remove the .htaccess, and it work fine after. My question is, is there a fix that will let me hotlink protection using .htaccess that would also work on mobile? Thanks in advance.

sorry, forgot to include.

.htaccess:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mydomain.com [NC]
RewriteRule \.(mp4|jpg|gif)$ - [NC,F,L]

Upvotes: 1

Views: 1786

Answers (1)

Jon Lin
Jon Lin

Reputation: 143926

You can add an exclusion for mobile user-agents, you can go here for the list of ones that you want to exclude. So what you'd end up with is something like this:

RewriteEngine on

# for android/ipad/iphone/BlackBerry/Nokia/Samsung/Windows Phone
RewriteCond %{HTTP_USER_AGENT} !(Android|iPad|iPhone|BlackBerry|Nokia|SAMSUNG|Windows\ Phone)

RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mydomain.com [NC]
RewriteRule \.(mp4|jpg|gif)$ - [NC,F,L]

Keep in mind that referers and user agents can be completely spoofed, so this is not a fool-proof way or preventing resource leeching.

Upvotes: 1

Related Questions