# =====================================================================
# MACKLUC ARTISANAL CHOCOLATIER - APACHE CONFIGURATION (.htaccess)
# Production-ready security, compression and URL handling
# =====================================================================

DirectoryIndex index.php index.html

# 1. PREVENT DIRECTORY LISTING
Options -Indexes

# 2. DEFAULT CHARSET
AddDefaultCharset UTF-8

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # Optional: Force HTTPS (Descomentar si el hosting no fuerza SSL automáticamente)
    # RewriteCond %{HTTPS} off
    # RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    # Block access to hidden files and sensitive directories
    RewriteRule "(^|/)\.(?!well-known)" - [F]
    RewriteRule "^database/" - [F,L]
    RewriteRule "^scratch/" - [F,L]
</IfModule>

# 3. BLOCK ACCESS TO SENSITIVE EXTENSIONS
<FilesMatch "\.(sql|md|env|json|lock|log|sh|bak)$">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order deny,allow
        Deny from all
    </IfModule>
</FilesMatch>

# 4. GZIP COMPRESSION
<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
    AddOutputFilterByType DEFLATE application/json
    AddOutputFilterByType DEFLATE image/svg+xml
</IfModule>

# 5. BROWSER CACHING FOR ASSETS
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault "access plus 1 month"
    ExpiresByType text/html "access plus 0 seconds"
    ExpiresByType text/css "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/webp "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"
    ExpiresByType font/woff2 "access plus 1 year"
</IfModule>

# 6. BASIC 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>
