# MyNTP — Apache 2.4 configuration for the static build (dist/).
# Requires: AllowOverride All (or at least FileInfo Indexes Options) for this directory.
# Modules used if present: mod_rewrite, mod_headers, mod_expires, mod_deflate, mod_mime.

Options -Indexes -MultiViews
DirectoryIndex index.html
# /fa → /fa/ (mod_dir default; stated explicitly)
DirectorySlash On
ErrorDocument 404 /404.html
AddDefaultCharset utf-8

<IfModule mod_mime.c>
    AddType application/manifest+json .webmanifest
    AddType font/woff2 .woff2
    AddType image/svg+xml .svg
    AddCharset utf-8 .html .css .js .json .webmanifest .xml .txt .svg
</IfModule>

# Canonical host: https://myntp.ir (only applies on the production host names)
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^(www\.)?myntp\.ir$ [NC]
    RewriteCond %{HTTPS} !=on [OR]
    RewriteCond %{HTTP_HOST} ^www\. [NC]
    RewriteRule ^ https://myntp.ir%{REQUEST_URI} [R=301,L]
</IfModule>

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

<IfModule mod_headers.c>
    Header always set X-Content-Type-Options "nosniff"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
    Header always set X-Frame-Options "DENY"
    Header always set Permissions-Policy "camera=(), microphone=(), geolocation=(), clipboard-write=(self)"
    Header always set Cross-Origin-Opener-Policy "same-origin"
    # No inline scripts or styles are used, so the policy can be strict.
    Header always set Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; font-src 'self'; connect-src 'self'; manifest-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'; upgrade-insecure-requests"
    Header always set Strict-Transport-Security "max-age=31536000" "expr=%{HTTPS} == 'on'"

    # Pages revalidate on every visit so deploys show up immediately.
    <FilesMatch "\.html$">
        Header set Cache-Control "no-cache"
    </FilesMatch>
    # Unversioned static files.
    <FilesMatch "\.(svg|png|jpg|webmanifest|xml|txt)$">
        Header set Cache-Control "public, max-age=86400"
    </FilesMatch>
    <Files "theme-init.js">
        Header set Cache-Control "public, max-age=3600"
    </Files>
</IfModule>

# Never serve other dotfiles.
<FilesMatch "^\.">
    Require all denied
</FilesMatch>
