PassengerEnabled off
# =====================================
# Django Security & Proxy Rewrite
# =====================================
# Enable RewriteEngine
<IfModule mod_rewrite.c>
    RewriteEngine On

    # ============================
    # Serve static files efficiently
    # ============================
    # Serve files from /staticfiles/ if they exist
    RewriteCond %{REQUEST_URI} ^/static/(.*)$
    RewriteCond %{DOCUMENT_ROOT}/staticfiles/%1 -f
    RewriteRule ^static/(.*)$ staticfiles/$1 [L]

    # Serve media files directly
    RewriteCond %{REQUEST_URI} ^/media/(.*)$
    RewriteCond %{DOCUMENT_ROOT}/media/%1 -f
    RewriteRule ^media/(.*)$ media/$1 [L]

    # ============================
    # Proxy all other requests to Django (Gunicorn)
    # ============================
    RewriteCond %{REQUEST_URI} !^/static/
    RewriteCond %{REQUEST_URI} !^/media/
    RewriteRule ^(.*)$ http://127.0.0.1:8000/$1 [P,L]
</IfModule>

# =====================================
# Proxy and Security Headers
# =====================================
ProxyPreserveHost On
ProxyPassReverse / http://127.0.0.1:8000/

<IfModule mod_headers.c>
    Header set X-Content-Type-Options "nosniff"
    Header set X-Frame-Options "SAMEORIGIN"
    Header set X-XSS-Protection "1; mode=block"

    # Cache control for static files
    <FilesMatch "\.(css|js|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$">
        Header set Cache-Control "public, max-age=31536000, immutable"
    </FilesMatch>

    # No cache for HTML files
    <FilesMatch "\.(html|htm)$">
        Header set Cache-Control "no-cache, no-store, must-revalidate"
        Header set Pragma "no-cache"
        Header set Expires "0"
    </FilesMatch>
</IfModule>

# =====================================
# Optional: PHP Handler (keep default)
# =====================================
<IfModule mime_module>
    AddHandler application/x-httpd-ea-php82 .php .php8 .phtml
</IfModule>

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php82” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php82 .php .php8 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
