apache2 Hotlink Protection (Image theft Block Access)

Post Reply
Brave Ye
系統管理員
Posts: 5659
Joined: 2025-11-08, 13:32
Location: Taiwan
Contact:

apache2 Hotlink Protection (Image theft Block Access)

Post by Brave Ye »

nano /var/www/html/.htaccess

Code: Select all

<IfModule mod_rewrite.c>
  RewriteEngine on
  # Allow requests with no referrer (direct access, firewalls, etc.)
  RewriteCond %{HTTP_REFERER} !^$
  # Allow requests from your own domain (replace 'yourdomain.com')
  RewriteCond %{HTTP_REFERER} !^https?://([^.]+\.?)?yourdomain\.com/.*$ [NC]
  # Block common image formats
  RewriteRule \.(gif|jpe?g|png|bmp|webp)$ - [F,NC,L]
</IfModule>
sudo a2enmod rewrite
sudo systemctl restart php8.5-fpm
sudo systemctl restart apache2
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest