# Rabtik Health production hardening (Apache/LiteSpeed).
Options -Indexes
ServerSignature Off

<IfModule mod_rewrite.c>
RewriteEngine On

# Keep source material, private verification notes and build output off the public site.
RewriteRule ^(?:content|scripts|output)(?:/|$) - [F,L,NC]

# One production host; local preview is preserved.
RewriteCond %{HTTP_HOST} ^(?:www\.)?(?:rabtikhealth\.com|saicareproviders\.com)(?::[0-9]+)?$ [NC]
RewriteCond %{HTTP_HOST} !^www\.rabtikhealth\.com$ [NC]
RewriteRule ^ https://www.rabtikhealth.com%{REQUEST_URI} [R=301,L,NE]

# Respect HTTPS terminated by a trusted hosting proxy.
RewriteCond %{HTTP_HOST} ^www\.rabtikhealth\.com$ [NC]
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP:X-Forwarded-Proto} !^https$ [NC]
RewriteRule ^ https://www.rabtikhealth.com%{REQUEST_URI} [R=301,L,NE]

# Canonical homepage; THE_REQUEST avoids redirecting internal rewrites.
RewriteCond %{THE_REQUEST} \s/+index\.html[?\s] [NC]
RewriteRule ^index\.html$ / [R=301,L]

# Service landing pages use clean canonical URLs.
RewriteCond %{THE_REQUEST} \s/+(physiotherapy-coventry|sports-physiotherapy-coventry|sports-massage-coventry|massage-coventry|ayurvedic-massage-coventry|online-physiotherapy|nurse-led-healthcare-coventry|iv-therapy-coventry|aesthetics-skin-coventry|online-pilates)\.html[?\s] [NC]
RewriteRule ^(physiotherapy-coventry|sports-physiotherapy-coventry|sports-massage-coventry|massage-coventry|ayurvedic-massage-coventry|online-physiotherapy|nurse-led-healthcare-coventry|iv-therapy-coventry|aesthetics-skin-coventry|online-pilates)\.html$ /$1 [R=301,L]

# TRACE can disclose request details through intermediaries and is not needed here.
RewriteCond %{REQUEST_METHOD} ^TRACE [NC]
RewriteRule .* - [F,L]

# Redirect encoded URLs to HTML pages
RewriteRule ^YWJvdXQuaHRtbA==$ /about.html [L]
RewriteRule ^c2VydmljZS5odG1s$ /service.html [L]
RewriteRule ^Y29udGFjdC5odG1s$ /contact.html [L]
RewriteRule ^aW5kZXg=$ /index.html [L]
RewriteRule ^cnavb.qcvu$ /terms.html [L]
RewriteRule ^wvspjf$ /policy.html [L]

# Redirect "/" to index.html
RewriteRule ^$ /index.html [L]

# Redirect retired template pages to their current destinations.
RewriteRule ^appointment(?:\.html)?$ /#appointment [R=301,L,NE]
RewriteRule ^feature(?:\.html)?$ /#why-choose-us [R=301,L,NE]
RewriteRule ^team(?:\.html)?$ /about.html#team [R=301,L,NE]
RewriteRule ^(?:blog|testimonial)(?:\.html)?$ / [R=301,L,NE]

# Hide ".html" from URLs
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^/]+)/?$ $1.html [L]

ErrorDocument 404 /404.html
</IfModule>

# Prevent accidental publication of backups, source maps, logs, and server secrets.
<FilesMatch "(?i)(^\.|\.(bak|backup|conf|config|dist|env|git|heic|ini|log|map|old|orig|pem|py|md|sql|tar|tgz|yml|yaml|zip)$)">
    Require all denied
</FilesMatch>

<IfModule mod_headers.c>
    Header always unset X-Powered-By
    Header always set Content-Security-Policy "default-src 'self'; base-uri 'self'; object-src 'none'; frame-ancestors 'none'; form-action 'self' https://formsubmit.co; script-src 'self' https://ajax.googleapis.com https://cdn.jsdelivr.net https://embed.tawk.to https://*.tawk.to; script-src-attr 'none'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://use.fontawesome.com https://cdn.jsdelivr.net https://cdnjs.cloudflare.com; font-src 'self' data: https://fonts.gstatic.com https://use.fontawesome.com https://cdn.jsdelivr.net https://cdnjs.cloudflare.com; img-src 'self' data: blob: https://*.tawk.to https://tawk.link; frame-src 'self' https://sai-care-providers-limited.uk2.cliniko.com https://www.youtube.com https://www.google.com https://*.tawk.to; connect-src 'self' https://embed.tawk.to https://*.tawk.to wss://*.tawk.to https://formsubmit.co; media-src 'self' blob:; worker-src 'self' blob:; manifest-src 'self'; upgrade-insecure-requests"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
    Header always set X-Content-Type-Options "nosniff"
    Header always set X-Frame-Options "DENY"
    Header always set X-XSS-Protection "0"
    Header always set Permissions-Policy "camera=(), microphone=(), geolocation=(), usb=(), browsing-topics=(), payment=(self \"https://sai-care-providers-limited.uk2.cliniko.com\")"
    Header always set Cross-Origin-Opener-Policy "same-origin-allow-popups"
    Header always set Strict-Transport-Security "max-age=31536000"
</IfModule>
