# =====================================================
# FLOWB0T NEXUS - Apache Configuration
# =====================================================

# Enable RewriteEngine
RewriteEngine On
RewriteBase /nexus/

# Force HTTPS (uncomment in production)
# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Handle Front Controller - allow existing files and directories
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L,QSA]

# Security Headers
<IfModule mod_headers.c>
    Header always set X-Content-Type-Options nosniff
    Header always set X-Frame-Options SAMEORIGIN
    Header always set X-XSS-Protection "1; mode=block"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

# Disable directory listing
Options -Indexes

# Protect sensitive files
<FilesMatch "^\.">
    Order allow,deny
    Deny from all
</FilesMatch>

<FilesMatch "\.(env|log|md|json)$">
    Order allow,deny
    Deny from all
</FilesMatch>

# Allow access to specific JSON files
<FilesMatch "^(package|composer)\.json$">
    Order allow,deny
    Allow from all
</FilesMatch>

# Protect config directory
<IfModule mod_rewrite.c>
    RewriteRule ^config/ - [F,L]
    RewriteRule ^core/ - [F,L]
    RewriteRule ^engine/ - [F,L]
    RewriteRule ^data/ - [F,L]
</IfModule>

# Allow access to exports directory (for downloads)
<Directory "exports">
    Options -Indexes
    AllowOverride None
    Require all granted
</Directory>

# PHP Settings (if allowed)
<IfModule mod_php.c>
    php_value upload_max_filesize 50M
    php_value post_max_size 50M
    php_value max_execution_time 300
    php_value max_input_time 300
    php_value memory_limit 512M
</IfModule>

# Compression
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json
</IfModule>

# Cache Control
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/svg+xml "access plus 1 month"
    ExpiresByType text/css "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 week"
    ExpiresByType application/x-javascript "access plus 1 week"
</IfModule>

# Error Documents
ErrorDocument 404 /nexus/index.php?page=dashboard
ErrorDocument 500 /nexus/index.php?page=dashboard
