Hotlink protection is a feature that prevents other websites from directly linking to your images, videos, or other media files. Without hotlink protection, other sites can use your bandwidth by embedding your content on their pages, which can slow down your website and increase your hosting costs. Enabling hotlink protection on OzSpeed’s hPanel is an effective way to safeguard your media files. Here’s how to set it up.
Method 1: Enable Hotlink Protection Using hPanel #
OzSpeed’s hPanel includes a built-in Hotlink Protection tool that makes it easy to prevent unauthorized linking of your content.
Step 1: Log in to hPanel #
- Go to ozspeed.com.au and log in to your hPanel Dashboard.
- Navigate to Security and click on “Hotlink Protection”.
Step 2: Configure Hotlink Protection #
- Enable the Hotlink Protection option.
- Add the domains you want to allow to access your content (e.g., your own domain like
yourdomain.com
).- By default, your domain will be added to the allow list, but you can add others as needed (e.g.,
subdomain.yourdomain.com
).
- By default, your domain will be added to the allow list, but you can add others as needed (e.g.,
- Specify the file types you want to protect (e.g.,
.jpg
,.png
,.gif
,.mp4
).
Example:
- File types:
.jpg, .jpeg, .png, .gif, .mp4
Step 3: Save the Changes #
- Click “Save” to apply the hotlink protection settings.
- Test your website to ensure your images and media are still displaying correctly.
Tip: #
- If your files are still being hotlinked after enabling protection, clear your browser cache and try again.
Method 2: Enable Hotlink Protection Using .htaccess
#
If you prefer a manual method or want more control, you can use the .htaccess
file to enable hotlink protection.
Step 1: Edit the .htaccess
File #
- Go to Files > File Manager in hPanel.
- Navigate to the public_html directory.
- Open the
.htaccess
file for editing. If it doesn’t exist, create a new one.
Step 2: Add Hotlink Protection Code #
Paste the following code into your .htaccess
file:
apacheCopy code# Enable hotlink protection
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^https://yourdomain.com/ [NC]
RewriteCond %{HTTP_REFERER} !^https://www.yourdomain.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule \.(jpg|jpeg|png|gif|mp4)$ - [F,NC]
Explanation: #
- RewriteEngine On: Enables the Apache rewrite engine.
- RewriteCond: Specifies conditions for the rule.
!^https://yourdomain.com/ [NC]
: Allows access only from your domain.!^$
: Allows direct access (e.g., typing the URL in the browser).
- RewriteRule: Blocks access to specified file types (e.g.,
.jpg
,.png
,.gif
,.mp4
).[F,NC]
: Returns a 403 Forbidden error if the conditions are met.
Step 3: Save and Test #
- Click Save to apply the changes.
- Visit your website to ensure that the images and media files are loading correctly.
- Try hotlinking an image on another site (or use an online HTML editor) to verify that the file is blocked.
Tip: #
- If your images aren’t loading on your own site, check the domain names in the
.htaccess
file to ensure they match your URLs (includingwww
andhttps
variations).
Method 3: Use a Content Delivery Network (CDN) for Hotlink Protection #
Many Content Delivery Networks (CDNs) like Cloudflare offer built-in hotlink protection.
How to Enable Hotlink Protection on Cloudflare: #
- Log in to your Cloudflare dashboard.
- Select your website and go to the Scrape Shield section.
- Toggle the Hotlink Protection setting to On.
Tip: #
- Cloudflare’s hotlink protection can be enabled with a single click and works well with other security features like DDoS protection.
Troubleshooting Tips #
- Images Not Displaying on Your Own Site:
- Ensure your domain and any subdomains are added to the allow list in the Hotlink Protection settings.
- Clear your browser cache and try reloading the page.
- Hotlink Protection Not Working:
- Verify that the
.htaccess
file is in the correct directory (public_html
). - Make sure the rewrite rules are correctly formatted and there are no conflicting rules.
- Verify that the
- File Types Not Protected:
- Double-check the list of protected file types in the
.htaccess
code or hPanel settings. Ensure all relevant file types (e.g.,.webp
,.svg
) are included.
- Double-check the list of protected file types in the
- Testing Hotlink Protection:
- Use an online HTML editor (e.g., JSFiddle) to create a test page that attempts to hotlink an image from your site. If the protection is working, the image will not load.
Additional Tips: #
- Customize the Error Message: Instead of showing a generic 403 error, redirect hotlinked requests to a custom error page or placeholder image.
- Example
.htaccess
code:
RewriteRule \.(jpg|jpeg|png|gif|mp4)$ https://yourdomain.com/placeholder.jpg [R,NC]
- Example
- Enable SSL: Make sure your website uses HTTPS to prevent mixed content issues when hotlink protection is enabled.
- Monitor Bandwidth Usage: Check your hosting analytics or CDN dashboard to monitor bandwidth usage and detect potential hotlinking activity.