# Piffers — Apache / Namecheap cPanel
DirectoryIndex index.html
Options -Indexes

<IfModule mod_rewrite.c>
  RewriteEngine On

  # HTTPS once the domain SSL certificate is active
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP:X-Forwarded-Proto} !=https
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

  # Same redirects as next.config.mjs (static export ignores those)
  RewriteRule ^our-services/?$ /what-we-do/ [R=301,L]
  RewriteRule ^contacts/?$ /contact-us/ [R=301,L]
  RewriteRule ^cookies/?$ /cookie-policy/ [R=301,L]
  RewriteRule ^privacy/?$ /privacy-policy/ [R=301,L]
  RewriteRule ^terms/?$ /terms-and-conditions/ [R=301,L]
  RewriteRule ^cctv/?$ /cctv-2/ [R=301,L]

  # Contact form posts to /api/contact — handled by PHP on shared hosting
  RewriteRule ^api/contact/?$ /contact.php [L]

  # /about-us → /about-us/ when that folder has an index.html
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_URI} !/$
  RewriteCond %{DOCUMENT_ROOT}/$1/index.html -f
  RewriteRule ^(.+?)$ /$1/ [R=301,L]
</IfModule>

ErrorDocument 404 /404.html
