# =============================================
# SPINEXCH CRM - .htaccess
# =============================================

# ========== DEFAULT INDEX ==========
DirectoryIndex index.php index.html

# ========== DISABLE DIRECTORY LISTING ==========
Options -Indexes

# ========== ENABLE REWRITE ==========
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
</IfModule>

# ========== ERROR PAGES ==========
ErrorDocument 403 /index.php
ErrorDocument 404 /index.php

# ========== 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>

# ========== BLOCK SENSITIVE FILES ==========
<FilesMatch "^(config\.php|\.htaccess|\.htpasswd|\.env|composer\.json|composer\.lock)$">
    Order Allow,Deny
    Deny from all
</FilesMatch>

# ========== BLOCK BACKUP FILES ==========
<FilesMatch "\.(bak|old|orig|save|swp|sql|log|txt|md)$">
    Order Allow,Deny
    Deny from all
</FilesMatch>

# ========== PHP SECURITY ==========
<IfModule mod_php.c>
    php_flag display_errors Off
    php_flag log_errors On
    php_value upload_max_filesize 10M
    php_value post_max_size 10M
    php_value max_execution_time 60
</IfModule>

# ========== GZIP COMPRESSION ==========
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
    AddOutputFilterByType DEFLATE application/javascript application/x-javascript
    AddOutputFilterByType DEFLATE application/json application/xml
</IfModule>

# ========== BROWSER CACHE ==========
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access 1 month"
    ExpiresByType image/jpeg "access 1 month"
    ExpiresByType image/png "access 1 month"
    ExpiresByType image/gif "access 1 month"
    ExpiresByType image/svg+xml "access 1 month"
    ExpiresByType image/x-icon "access 1 month"
    ExpiresByType text/css "access 1 month"
    ExpiresByType application/javascript "access 1 month"
    ExpiresByType application/x-javascript "access 1 month"
</IfModule>

# ========== UTF-8 ENCODING ==========
AddDefaultCharset UTF-8

# ========== BLOCK BAD BOTS ==========
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_USER_AGENT} (libwww-perl|wget|python|nikto|scan|winhttp|clshttp|loader) [NC]
    RewriteRule .* - [F,L]
</IfModule>

# ========== FORCE HTTPS ==========
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>