How to block all external elements loading using .htaccess?

Discussion in 'Apache' started by postcd, Mar 21, 2022.

  1. #1
    Hello,

    i want to block loading of all elements loaded from external sites. For example embeding images that are hosted on different domains.

    My failed attempt is:
    # Disable external content
    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http(s)?://(subdomain.)?mydomain.com [NC]
    RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mydomain.com [NC]
    RewriteRule \.(jpg|jpeg|png|gif|bmp|webp)$ - [F]
    Code (markup):
    In last line i have mentioned some extensions though i would prefer blocking everything, except for example filename externalcaptcha.js and otherexternal.file

    Thank You
     
    postcd, Mar 21, 2022 IP