DirectoryIndex app.php
# Content negotiation must not resolve /board before our rewrite rules do.
Options -MultiViews

RewriteEngine On

# Do not expose includes or database files through the web server.
RewriteRule ^(?:inc|data)(?:/|$) - [F,END]

# Canonical page URLs. THE_REQUEST prevents loops after an internal rewrite.
# Only GET/HEAD are redirected; legacy API URLs and POST bodies stay valid.
# Relative substitutions also work when installed below /retrowrap/ etc.
RewriteCond %{REQUEST_METHOD} ^(?:GET|HEAD)$
RewriteCond %{THE_REQUEST} \s/+[^?\s]*\.php(?:[?\s]) [NC]
RewriteRule ^(app|admin|board|archive|actions|report|privacy|setup/index|setup/init_db)\.php$ $1 [R=308,END]

# Only route known public pages and existing API scripts, never arbitrary PHP.
RewriteRule ^(app|admin|board|archive|actions|report|privacy)$ $1.php [END]
RewriteRule ^setup/$ setup/index.php [END]
RewriteRule ^setup/(index|init_db)$ setup/$1.php [END]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^api/([a-z][a-z0-9_]*)$ api/$1.php [END]
