RewriteEngine On

# Public tenant booking page: /site/{slug} -> public/site.php?slug={slug}
RewriteRule ^site/([a-z0-9\-]+)/?$ public/site.php?slug=$1 [L,QSA]

# Redirect explicit .php requests to clean URL
RewriteCond %{THE_REQUEST} \s/+(.+)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L]

# Internally rewrite clean URL to the .php file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]

# Block direct access to sensitive folders
RewriteRule ^(config|includes|database|whatsapp-listener)/ - [F,L]
