Hotlink File Prevention
Hotlink File Prevention
Description
Hotlink File Prevention (HFP) offers simple hotlink protection that can be turned on/off for individual files in the WordPress media library.
“Hotlinking” is when a file, such as an image or PDF, is linked to from another website or entered manually in a web browser’s location bar. HFP only allows your file to be viewed on your website.
Hotlink protection is provided via .htaccess rules in the wp-content/uploads directory.
Basic Usage
Once the HFP plugin is activated, you will have two new features in the media library:
- Within the Screen Options tab (list view only), check box for the “Hotlink Prevention” column.
- To protect a file, edit the file and scroll down to the checkbox labelled “Hotlink Protection”.
Any asset that is checked will have “Yes” displayed in the “Hotlink Prevention” column; otherwise, this column will be blank.
Note about “Open in new tab” option
When you use the “Open in new tab” option for links, WordPress adds rel="noreferrer", which effectively makes the link act like direct access, and the link will be blocked for files protected using HFP.
Installation
- Go to “Plugins > Add New” in the WordPress admin area.
- Search for “Hotlink File Prevention”.
- Install, then Activate the plugin.
For more installation options and instructions, see “Installing Plugins” on WordPress.org.
Faq
HFP creates an Apache .htaccess file in the wp-content/uploads directory. It sets a HTTP_REFERER check and RewriteRule for each file that has hotlink protection applied. Toggling hotlink protection on/off dynamically adds/removes RewriteRule statements.
Yes, it works with any file that you upload to the media library.
Here’s the deal: This plugin makes it harder for people to hotlink to your files, but if they are highly technical, they will be able to do things like fake the HTTP referrer.
The server must process rewrite rules in .htaccess. So HFP will work on Apache and LightSpeed servers, but not NGINX.
Reviews
Works Great! (read review below for exceptions)
By Rick Cheney (RCSTP) on November 20, 2024
THANK YOU for making this plugin. It works great EXCEPT your media library filenames cannot have hyphens in the filenames. Maybe they can have one or two hyphens, I don't know because I didn't test it but I found with four hyphens in the filename it didn't work.
Not working
By twentytwelveuser on June 2, 2024
The plugin is activated, but other site still shows pictures from my site.
RewriteRule 2017/03/Unity-Terrain03.png - [NC,L,F]
Still there is no effect
Added:
The problem was in hosting settings - they disabled htaccess and used nginx. So I have to enable manual mode to turn on htaccess:
- Connect to the site with SSH
- Edit the config file for your site (example: ~/etc/httpd/php80/site-address.conf):
<Directory /home/h12345678/site-address/docs/wp-content/uploads>
AllowOverride All
</Directory>
3. Use the plugin
Perfect Solution
By Mike Oliver (zephyrmike) on May 29, 2024
I had an image on one of my website demos linking to over 100k sites, this plugin worked perfectly to block it.
Very good
By trinhthidien on January 22, 2022
Exactly what I was looking for!
By Wolfgang Hanus (whanus) on September 8, 2021
the best
By user098242734 on June 18, 2021
Excellent
By Mostafa Shemeas on May 12, 2021
Changelog
2.0.0
- Track protected files in wp_options table instead of individual post meta
- Fixed htaccess rules to work with multiple protected files
- Use insert_with_markers() to handle writing to htaccess
- Added CSS for media library table column
- Added uninstall hook
1.1.0
- Modernized the code, and got it working again!
- Updated README
- Changed some strings, and made them translation-ready
- Moved Hotlink Protection column before Date
- Added deactivation hook to remove htaccess file
1.0.1
- commented out error reporting
- now uses just filename (followed by full path and name) in .htaccess; previously this was full path and location alone. Version 1.0.0 users should delete .htaccess from /uploads directory and rebuild file by clicking “update” on any file in Media Library that has “Yes” for Hotlink File Prevention.
1.0.0
- Development version and Alpha release.
