DirectoryIndex index.php index.html
Options -Indexes
RewriteEngine On

# Block direct public access to internal/runtime-private files.
RewriteRule ^(?:includes|sql|docs|scripts|tests|_packages|_private_exports|_private)(?:/|$) - [F,L]
RewriteRule ^(?:deploy-diagnostics|dashboard)\.php$ - [F,L]
RewriteRule ^templates/.*\.txt$ - [F,L]
RewriteRule ^(?!ads\.txt$|robots\.txt$)[^/]+\.(?:md|csv|json|txt)$ - [F,L]
RewriteRule (^|/)(?:config\.local\.php|\.env(?:\.[^/]+)?|php\.ini|\.user\.ini|.*\.(?:log|zip|bak|backup|sql|tmp|ini))$ - [F,L]

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Canonicalize direct PHP requests to clean public routes.
RewriteCond %{THE_REQUEST} \s/+index\.php[\s?] [NC]
RewriteRule ^index\.php$ / [R=301,L]
RewriteCond %{THE_REQUEST} \s/+about\.php[\s?] [NC]
RewriteRule ^about\.php$ /about [R=301,L]
RewriteCond %{THE_REQUEST} \s/+articles\.php[\s?] [NC]
RewriteRule ^articles\.php$ /articles [R=301,L]
RewriteCond %{THE_REQUEST} \s/+search\.php[\s?] [NC]
RewriteRule ^search\.php$ /search [R=301,L]
RewriteCond %{THE_REQUEST} \s/+topics\.php[\s?] [NC]
RewriteRule ^topics\.php$ /topics [R=301,L]
RewriteCond %{THE_REQUEST} \s/+topic\.php\?slug=([a-z0-9-]+) [NC]
RewriteRule ^topic\.php$ /topics/%1? [R=301,L]
RewriteCond %{THE_REQUEST} \s/+topic\.php[\s?] [NC]
RewriteRule ^topic\.php$ /topics [R=301,L]
RewriteCond %{THE_REQUEST} \s/+projects\.php[\s?] [NC]
RewriteRule ^projects\.php$ /projects [R=301,L]
RewriteCond %{THE_REQUEST} \s/+contact\.php[\s?] [NC]
RewriteRule ^contact\.php$ /contact [R=301,L]
RewriteCond %{THE_REQUEST} \s/+privacy(?:_policy)?\.php[\s?] [NC]
RewriteRule ^privacy(?:_policy)?\.php$ /privacy [R=301,L]
RewriteCond %{THE_REQUEST} \s/+editorial-policy\.php[\s?] [NC]
RewriteRule ^editorial-policy\.php$ /editorial-policy [R=301,L]
RewriteCond %{THE_REQUEST} \s/+methodology\.php[\s?] [NC]
RewriteRule ^methodology\.php$ /methodology [R=301,L]
RewriteCond %{THE_REQUEST} \s/+terms\.php[\s?] [NC]
RewriteRule ^terms\.php$ /terms [R=301,L]
RewriteCond %{THE_REQUEST} \s/+terms-index\.php[\s?] [NC]
RewriteRule ^terms-index\.php$ /term [R=301,L]
RewriteCond %{THE_REQUEST} \s/+shotgun\.php[\s?] [NC]
RewriteRule ^shotgun\.php$ /shotgun [R=301,L]
RewriteCond %{THE_REQUEST} \s/+minigames\.php[\s?] [NC]
RewriteRule ^minigames\.php$ /minigames [R=301,L]
RewriteCond %{THE_REQUEST} \s/+minigames-es\.php[\s?] [NC]
RewriteRule ^minigames-es\.php$ /minigames/es [R=301,L]
RewriteCond %{THE_REQUEST} \s/+minigames-fr\.php[\s?] [NC]
RewriteRule ^minigames-fr\.php$ /minigames/fr [R=301,L]

RewriteRule ^about/?$ about.php [L,QSA]
RewriteRule ^articles/?$ articles.php [L,QSA]
RewriteRule ^search/?$ search.php [L,QSA]
RewriteRule ^topics/?$ topics.php [L,QSA]
RewriteRule ^topics/([a-z0-9-]+)/?$ topic.php?slug=$1 [L,QSA]
RewriteRule ^projects/?$ projects.php [L,QSA]
RewriteRule ^contact/?$ contact.php [L,QSA]
RewriteRule ^privacy/?$ privacy.php [L,QSA]
RewriteRule ^editorial-policy/?$ editorial-policy.php [L,QSA]
RewriteRule ^methodology/?$ methodology.php [L,QSA]
RewriteRule ^terms/?$ terms.php [L,QSA]
RewriteRule ^term/?$ terms-index.php [L,QSA]
RewriteRule ^term/([a-z0-9-]+)/?$ term.php?slug=$1 [L,QSA]
RewriteRule ^minigames/shotgun/?$ /shotgun [R=301,L]
RewriteRule ^minigames/(es|fr)/shotgun/?$ /shotgun [R=301,L]
RewriteRule ^minigames/flight/?$ /minigames/flight-game [R=301,L]
RewriteRule ^shotgun/?$ shotgun/index.php [L,QSA]
RewriteRule ^minigames/?$ minigames.php [L,QSA]
RewriteRule ^minigames/es/?$ minigames-es.php [L,QSA]
RewriteRule ^minigames/fr/?$ minigames-fr.php [L,QSA]
RewriteRule ^minigames/es/([a-z0-9-]+)/?$ minigame-page.php?lang=es&slug=$1 [L,QSA]
RewriteRule ^minigames/fr/([a-z0-9-]+)/?$ minigame-page.php?lang=fr&slug=$1 [L,QSA]
RewriteRule ^minigames/([a-z0-9-]+)/?$ minigame-page.php?slug=$1 [L,QSA]
RewriteRule ^admin/?$ admin/index.php [L,QSA]
RewriteRule ^admin/dashboard/?$ admin/dashboard.php [L,QSA]
RewriteRule ^admin/terms/?$ admin/terms.php [L,QSA]
RewriteRule ^admin/settings/?$ admin/settings.php [L,QSA]
RewriteRule ^admin/logout/?$ admin/logout.php [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9-]+)/?$ article.php?slug=$1 [L,QSA]
ErrorDocument 404 /404.php
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript application/json
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 7 days"
ExpiresByType text/css "access plus 30 days"
ExpiresByType image/webp "access plus 90 days"
ExpiresByType image/jpg "access plus 90 days"
ExpiresByType image/jpeg "access plus 90 days"
ExpiresByType image/png "access plus 90 days"
</IfModule>
<IfModule mod_headers.c>
Header set X-Content-Type-Options "nosniff"
Header set X-Frame-Options "SAMEORIGIN"
Header set Referrer-Policy "strict-origin-when-cross-origin"
Header set Permissions-Policy "geolocation=(), microphone=(), camera=()"
Header set X-Permitted-Cross-Domain-Policies "none"
</IfModule>
