How restrict video to be open on direct url hit

i have client website of premium E-learning videos on wordpress. i have uploaded all the videos(MP4) in wp-content/uploads directory. i have problem since it is a premium video i want it such a way that no one can download or see the video with hitting direct file url eg. http://mywebsite.com/wp-content/uploads/2016/01/video.mp4

I want to restrict above url from function i also expect file to be work properly in my website though.

Topic content-restriction Wordpress

Category Web


You need to create a .htaccess file in order to block the file access from direct url entry. The below code should work for you.

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourwebsite\.com/ [NC]
RewriteCond %{REQUEST_URI} !hotlink\.(gif|png|jpg|doc|xls|pdf|html|htm|xlsx|docx|mp4|mov) [NC]
RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC]
RewriteRule .*\.(gif|png|jpg|doc|xls|pdf|html|htm|xlsx|docx|mp4|mov)$ http://yourwebsite.com/ [NC]

There is also a previous post on this in the Wordpress Stack exchange on this LINK

The best way to protect uploaded media in WordPress?

Hope that helps.

Andy

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.