# =====================================================================
# Spartan Diesel: Apache / cPanel server settings
# This file is optional but recommended. It works on standard Apache
# shared hosting (including GoDaddy cPanel hosting). Files starting with
# a dot can be hidden in some file managers: enable "show hidden files".
# If anything here causes a "500 Internal Server Error", remove the
# section that the host doesn't support.
# =====================================================================

# --- Custom 404 page --------------------------------------------------
ErrorDocument 404 /404.html

# --- Force HTTPS and the non-www domain -------------------------------
# Enable only after the SSL certificate is active on spartandiesel.ca.
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTPS} off [OR]
  RewriteCond %{HTTP_HOST} ^www\. [NC]
  RewriteRule ^ https://spartandiesel.ca%{REQUEST_URI} [L,R=301]
</IfModule>

# --- Keep partials crawlable (Google needs them to render pages)
#     but out of search results ----------------------------------------
<IfModule mod_headers.c>
  <If "%{REQUEST_URI} =~ m#^/partials/#">
    Header set X-Robots-Tag "noindex"
  </If>
</IfModule>

# --- Correct content types --------------------------------------------
AddType image/webp .webp
AddType font/woff2 .woff2
AddType application/manifest+json .webmanifest

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

# --- Browser caching --------------------------------------------------
# HTML, partials and config.js stay short so content edits appear quickly.
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 hour"
  ExpiresByType text/html "access plus 0 seconds"
  ExpiresByType text/css "access plus 7 days"
  ExpiresByType application/javascript "access plus 1 hour"
  ExpiresByType text/javascript "access plus 1 hour"
  ExpiresByType image/webp "access plus 30 days"
  ExpiresByType image/png "access plus 30 days"
  ExpiresByType image/jpeg "access plus 30 days"
  ExpiresByType image/x-icon "access plus 30 days"
  ExpiresByType font/woff2 "access plus 1 year"
</IfModule>

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

# --- No directory listings --------------------------------------------
Options -Indexes
