<IfModule mod_rewrite.c>
    RewriteEngine On
    DirectoryIndex index.php index.html
    RewriteBase /

    # Serve existing files or directories directly
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]

    # Remove trailing slashes from URLs
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Clean URL mapping: map extensionless requests to .php files if they exist
    RewriteCond %{DOCUMENT_ROOT}/$1.php -f
    RewriteRule ^(.*)$ $1.php [L,QSA]
</IfModule>

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

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/jpg "access plus 1 year"
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/gif "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"
  ExpiresByType audio/mpeg "access plus 1 year"
  ExpiresByType audio/mp3 "access plus 1 year"
  ExpiresByType audio/wav "access plus 1 year"
  ExpiresByType font/ttf "access plus 1 year"
  ExpiresByType font/woff2 "access plus 1 year"
  ExpiresByType application/javascript "access plus 1 month"
  ExpiresByType text/css "access plus 1 month"
</IfModule>

<IfModule mod_headers.c>
  <FilesMatch "\.(ico|jpe?g|png|gif|webp|svg|mp3|wav|ttf|woff2)$">
    Header set Cache-Control "max-age=31536000, public, immutable"
  </FilesMatch>
</IfModule>
