# net2ftp v2 — Apache settings (DocumentRoot must point to this public/ folder)
#
# Every directive is wrapped in <IfModule> so that a missing Apache module never causes
# "500 Internal Server Error". If the server uses "AllowOverride None", this file is ignored
# and net2ftp still works (only the extra security headers and compression are missing).
# Note: "Options -Indexes" is intentionally absent: it causes a 500 error when AllowOverride
# does not include Options. index.html makes directory listings impossible anyway.

<IfModule mod_dir.c>
    DirectoryIndex index.html
</IfModule>

# robots.txt with the sitemap address (see robots.php); without mod_rewrite the static robots.txt is served.
# sitemap.xml is a friendlier name for sitemap.php.
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^robots\.txt$ robots.php [L]
    RewriteRule ^sitemap\.xml$ sitemap.php [L]
</IfModule>

<IfModule mod_headers.c>
    Header always set X-Content-Type-Options "nosniff"
    Header always set X-Frame-Options "DENY"
    Header always set Referrer-Policy "same-origin"
    Header always set Permissions-Policy "camera=(), microphone=(), geolocation=()"
    # Keep in step with the <meta http-equiv="Content-Security-Policy"> in index.html (browsers apply both).
    # Scripts are strictly limited to this site. Inline *styles* are allowed because the code editor
    # (CodeMirror) injects its base styles at runtime; all displayed content is escaped, so this is low-risk.
    <FilesMatch "\.(html)$">
        Header set Content-Security-Policy "default-src 'self'; img-src 'self' data: blob:; style-src 'self' 'unsafe-inline'; script-src 'self'; connect-src 'self'; object-src 'none'; frame-ancestors 'none'; base-uri 'none'; form-action 'self'"
        Header set Cache-Control "no-cache"
    </FilesMatch>
    <FilesMatch "\.(css|js|svg|png|woff2)$">
        Header set Cache-Control "public, max-age=604800"
    </FilesMatch>
</IfModule>

<IfModule mod_mime.c>
    AddType text/javascript .js
    AddType image/svg+xml .svg
</IfModule>

<IfModule mod_deflate.c>
    <IfModule mod_filter.c>
        AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript application/json image/svg+xml
    </IfModule>
</IfModule>

# PHP as an Apache module (mod_php). For PHP-FPM / CGI the same values are in .user.ini.
# Uploads are chunked by the browser (8 MB slices), so these limits only need to exceed one chunk.
<IfModule mod_php.c>
    php_value upload_max_filesize 16M
    php_value post_max_size 20M
    php_value max_execution_time 600
    php_value memory_limit 256M
</IfModule>
