# ==========================================================
#  ShakaZulu Store — Apache / LiteSpeed configuration
# ==========================================================

# No directory listings
Options -Indexes
DirectoryIndex index.php

ErrorDocument 404 /404.php

<IfModule mod_rewrite.c>
    RewriteEngine On
    # If the site lives in a sub-folder, set it here, e.g. RewriteBase /shakazulu-store/
    RewriteBase /

    # Force HTTPS (uncomment once SSL is active)
    # RewriteCond %{HTTPS} off
    # RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    # Block private folders and hidden files
    RewriteRule ^(config|data|includes)(/|$) - [F,L]
    RewriteRule (^|/)\. - [F,L]

    # Clean URLs: /about -> pages/about.php
    RewriteRule ^(about|collection|contact|faq|privacy|terms)/?$ pages/$1.php [L,QSA]

    # Redirect old direct URLs to clean ones (only on the original request)
    RewriteCond %{THE_REQUEST} \s/+pages/(about|collection|contact|faq|privacy|terms)\.php[\s?]
    RewriteRule ^ %1 [R=301,L]
</IfModule>

# Protect sensitive file types
<FilesMatch "\.(md|log|ini|sh|sql|bak|dist|lock|json)$">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
</FilesMatch>

# Security headers (PHP also sends these; this covers static files)
<IfModule mod_headers.c>
    Header always set X-Content-Type-Options "nosniff"
    Header always set X-Frame-Options "SAMEORIGIN"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
    Header always unset X-Powered-By
</IfModule>

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

# Browser caching (CSS/JS are cache-busted with ?v=filemtime)
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault "access plus 1 hour"
    ExpiresByType text/html "access plus 0 seconds"
    ExpiresByType text/css "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 year"
    ExpiresByType text/javascript "access plus 1 year"
    ExpiresByType image/webp "access plus 6 months"
    ExpiresByType image/jpeg "access plus 6 months"
    ExpiresByType image/png "access plus 6 months"
    ExpiresByType image/svg+xml "access plus 6 months"
</IfModule>

<IfModule mod_mime.c>
    AddType image/webp .webp
</IfModule>
