# ============================================================
# ZAIAHTRIX2 - INFINITYFREE COMPATIBLE .htaccess
# Uses Apache 2.4 syntax (Require all denied)
# ============================================================

# Disable directory listing
Options -Indexes

# Set default files
DirectoryIndex index.php index.html

# ============================================================
# SECURITY HEADERS
# ============================================================

<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"
    Header set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

# ============================================================
# HIDE SENSITIVE FILES (Apache 2.4 syntax)
# ============================================================

<FilesMatch "^\.">
    Require all denied
</FilesMatch>

<FilesMatch "\.(env|env\.example|gitignore|md|json|lock|xml|yml|yaml|ini|log|sh|sql|bak|backup|old|tmp|temp)$">
    Require all denied
</FilesMatch>

<FilesMatch "^(config\.php|database\.php|bootstrap\.php|SettingsHelper\.php)$">
    Require all denied
</FilesMatch>

# ============================================================
# PHP SETTINGS
# ============================================================

<IfModule mod_php7.c>
    php_flag display_errors Off
    php_flag display_startup_errors Off
    php_value upload_max_filesize 10M
    php_value post_max_size 10M
    php_value max_execution_time 60
    php_flag session.cookie_httponly On
    php_flag session.use_only_cookies On
</IfModule>

# ============================================================
# CACHING & COMPRESSION
# ============================================================

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType text/javascript "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/svg+xml "access plus 1 month"
    ExpiresByType image/x-icon "access plus 1 year"
    ExpiresByType font/woff "access plus 1 year"
    ExpiresByType font/woff2 "access plus 1 year"
</IfModule>

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>

# ============================================================
# REWRITE RULES
# ============================================================

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Block suspicious requests
    RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
    RewriteRule .* - [F]
</IfModule>
# Canonical production hostname: preserve all paths while redirecting the legacy domain.
<IfModule mod_rewrite.c>
    RewriteCond %{HTTP_HOST} ^(www\.)?zaiahtrix2\.ct\.ws$ [NC]
    RewriteRule ^(.*)$ https://zaiahtrix2.online/$1 [R=301,L,NE]
</IfModule>

# Never expose one-time schema mutation helpers directly over HTTP.
<FilesMatch "^(apply_schema_|deploy_smoke_check\.php|connect_audit\.php|production_smoke_test\.php)$">
    Require all denied
</FilesMatch>
