# -------------------------------------------------------
# AIClinTrack – Apache configuration for Hostinger
# -------------------------------------------------------

Options -MultiViews

# llms.txt / robots.txt contain UTF-8 punctuation
AddDefaultCharset UTF-8
AddCharset UTF-8 .txt .xml
RewriteEngine On

# Serve pre-compressed Brotli files if available
<IfModule mod_brotli.c>
    AddType application/x-httpd-php .php
    AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css
    AddOutputFilterByType BROTLI_COMPRESS application/javascript application/json
    AddOutputFilterByType BROTLI_COMPRESS image/svg+xml application/xml
</IfModule>

# Gzip compression fallback
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml
    AddOutputFilterByType DEFLATE text/css application/javascript
    AddOutputFilterByType DEFLATE application/json application/xml
    AddOutputFilterByType DEFLATE image/svg+xml font/ttf font/otf
</IfModule>

# Browser caching
<IfModule mod_expires.c>
    ExpiresActive On

    # Images
    ExpiresByType image/jpeg             "access plus 1 year"
    ExpiresByType image/jpg              "access plus 1 year"
    ExpiresByType image/png              "access plus 1 year"
    ExpiresByType image/gif              "access plus 1 year"
    ExpiresByType image/webp             "access plus 1 year"
    ExpiresByType image/svg+xml         "access plus 1 year"
    ExpiresByType image/x-icon          "access plus 1 year"

    # Fonts
    ExpiresByType font/ttf               "access plus 1 year"
    ExpiresByType font/otf               "access plus 1 year"
    ExpiresByType font/woff              "access plus 1 year"
    ExpiresByType font/woff2             "access plus 1 year"

    # CSS / JS (hashed filenames, safe to cache long-term)
    ExpiresByType text/css               "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 year"
    ExpiresByType application/json       "access plus 5 minutes"

    # HTML (always revalidate)
    ExpiresByType text/html              "access plus 0 seconds"
</IfModule>

# Security headers
<IfModule mod_headers.c>
    # Prevent MIME type sniffing
    Header always set X-Content-Type-Options "nosniff"

    # Clickjacking protection
    Header always set X-Frame-Options "SAMEORIGIN"

    # XSS protection (legacy browsers)
    Header always set X-XSS-Protection "1; mode=block"

    # Referrer policy
    Header always set Referrer-Policy "strict-origin-when-cross-origin"

    # Permissions policy – lock down unused browser features
    Header always set Permissions-Policy "camera=(), microphone=(), geolocation=(), payment=()"

    # Remove server signature
    Header unset Server
    Header unset X-Powered-By

    # Cache-Control for hashed assets (immutable = no revalidation)
    <FilesMatch "\.(js|css|woff2?|ttf|otf|png|jpg|jpeg|gif|webp|svg|ico)$">
        Header set Cache-Control "public, max-age=31536000, immutable"
    </FilesMatch>

    # No-cache for HTML so updated deploys are picked up immediately
    <FilesMatch "\.html$">
        Header set Cache-Control "no-cache, no-store, must-revalidate"
        Header set Pragma "no-cache"
        Header set Expires "0"
    </FilesMatch>
</IfModule>

# Not-found handling
# Every marketing route is prerendered into its own directory (e.g.
# /ctms/index.html), so DirectoryIndex serves them on hard refresh. Unknown
# paths get the prerendered, noindex 404 page with a real 404 status.
ErrorDocument 404 /404.html

# Disable directory listing
Options -Indexes

# Deny access to dot-files (e.g. .env, .git)
<FilesMatch "^\.">
    Order allow,deny
    Deny from all
</FilesMatch>

# -------------------------------------------------------
# STAGING ONLY – block indexing of non-production deploys.
# Uncomment the block below on staging/preview hosts ONLY.
# It MUST remain commented out in production so the live site
# stays indexable. Never ship this enabled to aiclintrack.com.
# -------------------------------------------------------
# <IfModule mod_headers.c>
#     Header always set X-Robots-Tag "noindex, nofollow"
# </IfModule>
