# Apache 2.4 / cPanel. Merge with existing host rules; keep the /app portal intact.
Options -Indexes
DirectoryIndex index.php
ErrorDocument 404 /404.php

<IfModule mod_env.c>
    SetEnv VIDA_ENV production
    # Enable only after verifying the host mail transport and domain mailbox:
    # SetEnv VIDA_SEND_MAIL 1
</IfModule>

<FilesMatch "(?i)^secret-config(?:\.example)?\.php$">
    Require all denied
</FilesMatch>

<IfModule mod_rewrite.c>
    RewriteEngine On
    # Existing portal applications retain their own routing and configuration.
    RewriteRule ^app(?:/|$) - [L]

    RewriteRule (^|/)\.(?!well-known(?:/|$)) - [F,L]
    RewriteRule ^includes(?:/|$) - [F,L,NC]
    RewriteRule ^router\.php$ - [F,L,NC]
    RewriteRule ^[^/]+\.(?:zip|7z|tar|gz|sql|bak|old|log|ini|md)$ - [F,L,NC]
    RewriteRule ^data/uploads/(?:[A-Za-z0-9_-]+/)*[A-Za-z0-9_.-]+\.(?:png|jpe?g|gif|webp|avif)$ - [L,NC]
    RewriteRule ^data(?:/|$) - [F,L,NC]

    # Restrict HTTPS redirection to the intended production domain.
    RewriteCond %{HTTP_HOST} ^(?:www\.)?vida\.ng$ [NC]
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC]
    RewriteRule ^ https://www.vida.ng%{REQUEST_URI} [R=302,L,NE]

    RewriteRule ^sitemap\.xml$ sitemap.php [L]
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteCond %{DOCUMENT_ROOT}/$1.php -f
    RewriteRule ^([A-Za-z0-9_-]+)/?$ $1.php [L,QSA]
</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 "SAMEORIGIN"
</IfModule>
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/css application/javascript application/json image/svg+xml
</IfModule>
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css "access plus 7 days"
    ExpiresByType application/javascript "access plus 7 days"
    ExpiresByType image/webp "access plus 30 days"
    ExpiresByType image/png "access plus 30 days"
    ExpiresByType image/jpeg "access plus 30 days"
    ExpiresByType font/woff2 "access plus 1 year"
</IfModule>
