# ===== AXIS IT website =====
Options -Indexes
DirectoryIndex index.php
ErrorDocument 404 /404.php

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  # Force HTTPS and www (remove these 4 lines if you have no SSL yet)
  RewriteCond %{HTTPS} off [OR]
  RewriteCond %{HTTP_HOST} !^www\. [NC]
  RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
  RewriteRule ^ https://www.%1%{REQUEST_URI} [L,R=301]

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

  # Redirect /page.php to /page (clean URLs), except the form handler
  RewriteCond %{THE_REQUEST} \s/([^\s?]+)\.php[\s?] [NC]
  RewriteCond %1 !^(send-mail|captcha)$ [NC]
  RewriteRule ^ /%1 [R=301,L]

  # Serve /page from page.php
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME}.php -f
  RewriteRule ^([A-Za-z0-9\-]+)/?$ $1.php [L]
</IfModule>

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

# ----- Browser caching (assets are versioned with ?v=) -----
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 hour"
  ExpiresByType text/css "access plus 1 year"
  ExpiresByType application/javascript "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"
  ExpiresByType font/woff2 "access plus 1 year"
  ExpiresByType text/html "access plus 0 seconds"
</IfModule>

# ----- Security headers -----
<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"
  Header always set Permissions-Policy "camera=(), microphone=(), geolocation=()"
  <FilesMatch "\.(css|js|webp|png|svg|woff2)$">
    Header set Cache-Control "public, max-age=31536000, immutable"
  </FilesMatch>
</IfModule>

# captcha.php returns a fresh question every time: never cache it
<IfModule mod_headers.c>
  <Files "captcha.php">
    Header set Cache-Control "no-store, max-age=0"
  </Files>
</IfModule>

AddType font/woff2 .woff2

# ----- Protect config and hidden files -----
<FilesMatch "^(config\.php|bootstrap\.php|\.)">
  Require all denied
</FilesMatch>
