Options -Indexes

# ── Protect sensitive files ──────────────────────────────────
<Files "config.php">
    Order Allow,Deny
    Deny from all
</Files>
<Files "config.local.php">
    Order Allow,Deny
    Deny from all
</Files>
<Files "*.sql">
    Order Allow,Deny
    Deny from all
</Files>
<Files ".env">
    Order Allow,Deny
    Deny from all
</Files>

# Block diagnostic/setup/test scripts and dotfiles from web access
<FilesMatch "(^\.|_test\.php$|^setup\.php$|^ch\.php$|\.(env|ini|log|md|sh|bak|dist|example)$)">
    Order Allow,Deny
    Deny from all
</FilesMatch>

# ── URL Routing ──────────────────────────────────────────────
<IfModule mod_rewrite.c>
    RewriteEngine On

    # Dynamically set RewriteBase from script path
    # Works whether installed at root (/) or subdirectory (/rsvp-system/)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    # Route /event/{slug} → event/index.php?slug={slug}
    RewriteRule ^event/([a-z0-9_\-]+)/?$ event/index.php?slug=$1 [L,QSA]
</IfModule>
