RewriteEngine On
RewriteBase /

# Cache static assets
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/jpeg "access plus 30 days"
  ExpiresByType image/png "access plus 30 days"
  ExpiresByType image/webp "access plus 30 days"
  ExpiresByType text/css "access plus 7 days"
  ExpiresByType application/javascript "access plus 7 days"
</IfModule>

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

# Protect config
RewriteRule ^config/ - [F,L]
RewriteRule ^includes/ - [F,L]
RewriteRule ^database/ - [F,L]
RewriteRule ^pages/ - [F,L]

# Admin files are real PHP files
RewriteCond %{REQUEST_URI} ^/admin/ [NC]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

# Existing files
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# Front controller
RewriteRule ^ index.php [QSA,L]
