# Seachel Ltd — cPanel / Apache configuration
# Installed at: https://seachel.mu/ocean/

# ------------------------------------------------------------------
# LiteSpeed server cache: OFF for this site.
# The site is static and fast; the server cache only caused old
# "not found" pages to be served after updates.
# ------------------------------------------------------------------
<IfModule LiteSpeed>
  CacheLookup off
</IfModule>

Options -Indexes -MultiViews
DirectoryIndex index.html

# ------------------------------------------------------------------
# Clean URLs — /ocean/products instead of /ocean/products.html
# If the site ever moves out of /ocean, update the three /ocean paths
# below (and ErrorDocument at the bottom).
# ------------------------------------------------------------------
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /ocean/

  # /ocean/index.html -> /ocean/
  RewriteCond %{THE_REQUEST} \s/+ocean/index\.html[\s?] [NC]
  RewriteRule ^ /ocean/ [R=301,L]

  # /ocean/page.html -> /ocean/page  (query string and #fragment kept)
  RewriteCond %{THE_REQUEST} \s/+ocean/([^?\s]+)\.html[\s?] [NC]
  RewriteRule ^ /ocean/%1 [R=301,L]

  # /ocean/products/ -> /ocean/products
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.+)/$ /ocean/$1 [R=301,L]

  # serve the .html file behind a bare name
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^([A-Za-z0-9_-]+)$ $1.html [L]
</IfModule>

<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 "geolocation=(), microphone=(), camera=(), payment=()"
  Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains" env=HTTPS
</IfModule>

# ------------------------------------------------------------------
# Force HTTPS.
# Leave this commented out until Cloudflare SSL/TLS mode is set to
# "Full (strict)" and the origin certificate is installed in cPanel.
# With "Flexible" this rule causes an infinite redirect loop.
# ------------------------------------------------------------------
# <IfModule mod_rewrite.c>
#   RewriteEngine On
#   RewriteCond %{HTTPS} !=on
#   RewriteCond %{HTTP:X-Forwarded-Proto} !https
#   RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# </IfModule>

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
  ExpiresByType font/woff2 "access plus 1 year"
  ExpiresByType image/jpeg "access plus 6 months"
  ExpiresByType image/png "access plus 6 months"
  ExpiresByType image/svg+xml "access plus 6 months"
  ExpiresByType text/html "access plus 0 seconds"
</IfModule>

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

<IfModule mod_mime.c>
  AddType font/woff2 .woff2
</IfModule>

# Never serve the enquiry log or config through the web server.
<FilesMatch "\.(jsonl|log|ini|md)$">
  <IfModule mod_authz_core.c>
    Require all denied
  </IfModule>
  <IfModule !mod_authz_core.c>
    Order allow,deny
    Deny from all
  </IfModule>
</FilesMatch>

ErrorDocument 404 /ocean/404.html

# Block direct web access to the enquiry log and mail config.
<FilesMatch "^(config\.php|enquiries-.*\.jsonl)$">
  <IfModule mod_authz_core.c>
    Require all denied
  </IfModule>
  <IfModule !mod_authz_core.c>
    Order allow,deny
    Deny from all
  </IfModule>
</FilesMatch>
