• Resolved kseniyasqo

    (@kseniyasqo)


    Hello,

    I need to protect files from direct download (in case someone guesses the filename) only for one directory on subdomain subsite in multisite installation.

    I tried placing the following .htaccess into subdirectory (subsite.domain.wpengine.com replaces my real subsuite url):

    <IfModule mod_rewrite.c>
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g?|png|pdf|msi|deb|rpm|txt)$ [NC]
    RewriteCond %{HTTP_REFERER} !^https?://([^.]+\.)?subsite.domain.wpengine.com\. [NC]
    RewriteRule \.(gif|jpe?g?|png|pdf|msi|deb|rpm|txt)$ - [F,NC,L]
    </ifModule>

    This doesn’t work.

    I also tried to add rewrite rules to the global WP htaccess (as per https://wordpress.stackexchange.com/questions/48623/protect-uploads-in-multisite):

    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    
    # add a trailing slash to /wp-admin
    RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
    RewriteRule ^(.*\.php)$ $1 [L]
    RewriteRule . index.php [L]
    
    # added hotlink protection rules
    RewriteCond %{HTTP_HOST} ^subsite.domain.wpengine\.com
    RewriteCond %{SCRIPT_FILENAME} ^([_0-9a-zA-Z-]+/)?folder-name/(.+)
    RewriteRule ^([_0-9a-zA-Z-]+/)?folder-name/(.+) - [L]

    Not working either ??

    Anyone knows the solution here? Thanks!

    Another concern – for now, the domain has not yet been mapped to avoid displaying wpengine part
    How would I incorporate this change after? Thanks in advance!

Viewing 1 replies (of 1 total)
  • Thread Starter kseniyasqo

    (@kseniyasqo)

    Alright, everything turned out much simpler.

    I just put the following .htaccess file in the directory I want to protect:

    Order allow, deny
    Deny from all

    Since the plugin I use (File Away, by the way an amazing plugin with amazing support) has access to the folder anyway, everything works as required – you can access and download the files from the website, but unable to access them by direct URL (even if you are logged in to the website at this time).

Viewing 1 replies (of 1 total)
  • The topic ‘Hotlink protection of directory in subsite’ is closed to new replies.