# File: assets/uploads/.htaccess, the no-PHP rule and the cache rule of the uploads folder.
# Purpose: removes every PHP handler inside assets/uploads/ beside the name rule of the root
# .htaccess: a stored file is served and never run. Denies the markup types a browser runs script
# from, sends a sandboxing Content-Security-Policy with every file, lets a browser and a shared cache
# keep an image or a video 30 days, and keeps the folder in every upload that drops empty folders.
# Defines: nothing; Apache directives
# Doc: docs/notes/updates.plexcms.com/packages/plexcms-core/assets/uploads/.htaccess.md
<IfModule mod_php.c>
    php_flag engine off
</IfModule>
RemoveHandler .php .phtml .phar .php5 .php7 .php8 .pht .phps .shtml .cgi .pl .py
RemoveType .php .phtml .phar .php5 .php7 .php8 .pht .phps .shtml .cgi .pl .py
<FilesMatch "\.(php|phtml|phar|php[0-9]|pht|phps|shtml|cgi|pl|py)(\.|$)">
    Require all denied
</FilesMatch>
# FileStore refuses these 5 extensions; a file of them written into the folder by other means is not served.
<FilesMatch "(?i)\.(html?|xhtml|svg|xml)$">
    Require all denied
</FilesMatch>
# A served file runs no script and loads nothing from another origin, whatever type the browser reads it as.
<IfModule mod_headers.c>
    Header set Content-Security-Policy "default-src 'none'; img-src 'self'; style-src 'unsafe-inline'; sandbox"
</IfModule>
# A stored file keeps its random name for life: an image or a video answers a public cache of 30 days.
<FilesMatch "(?i)\.(jpe?g|png|webp|gif|ico|mp4)$">
    <IfModule mod_expires.c>
        ExpiresActive On
        ExpiresDefault "access plus 30 days"
    </IfModule>
    <IfModule mod_headers.c>
        Header set Cache-Control "public, max-age=2592000"
    </IfModule>
</FilesMatch>
