Options -Indexes
DirectoryIndex index.php
AddDefaultCharset UTF-8

<IfModule mod_rewrite.c>
RewriteEngine On

# Block direct access to internal folders
RewriteRule ^(includes|pages|cache|admin/pages)(/|$) - [F,L]

# Admin clean URLs: /admin, /admin/settings
RewriteRule ^admin/?$ admin/index.php [L,QSA]
RewriteRule ^admin/([a-z]+)/?$ admin/index.php?p=$1 [L,QSA]

# Hide .php extension: /file.php -> /file (GET only, POST bodies are never redirected)
RewriteCond %{REQUEST_METHOD} =GET
RewriteCond %{THE_REQUEST} \s/+((?:[^\s?]*/)?)index\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
RewriteCond %{REQUEST_METHOD} =GET
RewriteCond %{THE_REQUEST} \s/+([^\s?]+)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]

# /file -> file.php (internal)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

# SEO
RewriteRule ^sitemap\.xml$ index.php?route=sitemap.xml [L]
RewriteRule ^robots\.txt$ index.php?route=robots.txt [L]

# Front clean URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9\-]+)/?$ index.php?route=$1 [L,QSA]
</IfModule>

<FilesMatch "\.(sql|log|lock|md|ini)$">
  Require all denied
</FilesMatch>

<IfModule mod_headers.c>
  Header always set X-Content-Type-Options "nosniff"
  Header always set X-Frame-Options "SAMEORIGIN"
  Header always set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

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

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType text/css "access plus 7 days"
  ExpiresByType application/javascript "access plus 7 days"
  ExpiresByType image/png "access plus 30 days"
  ExpiresByType image/svg+xml "access plus 30 days"
  ExpiresByType image/x-icon "access plus 30 days"
  ExpiresByType image/webp "access plus 30 days"
  ExpiresByType image/jpeg "access plus 30 days"
</IfModule>
