# PB Cambridge Consult — Root Apache/LiteSpeed Configuration
# PHP front-controller routing + legacy .html redirects + security headers
#
# NOTE FOR LITESPEED/cPANEL HOSTS: LiteSpeed (LSWS) emulates mod_rewrite for
# .htaccess compatibility, so the directives below work unchanged. If clean
# URLs (e.g. /about) 404 after moving hosts, the cause is almost always one
# of: (1) this file didn't survive the migration — it's a hidden dotfile in
# most FTP clients/File Managers, (2) AllowOverride is restricted for this
# account — ask your host to confirm "AllowOverride All" / rewrite is
# enabled, or (3) these files were uploaded into a subfolder instead of
# directly into public_html. Run /debug-routing.php (included) to check.

# ── Explicit default document (some hosts default to index.html first) ──
DirectoryIndex index.php index.html

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  # ── Force HTTPS ─────────────────────────────────────────────
  # Checks both the standard HTTPS var and X-Forwarded-Proto, since some
  # LiteSpeed/cPanel setups terminate SSL behind a proxy where %{HTTPS}
  # alone can misreport and cause a redirect loop.
  RewriteCond %{HTTPS} off
  RewriteCond %{HTTP:X-Forwarded-Proto} !https
  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

  # ── Legacy .html URLs → new clean routes (301, preserves SEO) ──
  RewriteRule ^index\.html$ / [R=301,L,NC]
  RewriteRule ^about\.html$ /about [R=301,L,NC]
  RewriteRule ^accommodation\.html$ /accommodation [R=301,L,NC]
  RewriteRule ^application-support\.html$ /application-support [R=301,L,NC]
  RewriteRule ^blog-accommodation\.html$ /blog-accommodation [R=301,L,NC]
  RewriteRule ^blog-canada-pr\.html$ /blog-canada-pr [R=301,L,NC]
  RewriteRule ^blog-chevening\.html$ /blog-chevening [R=301,L,NC]
  RewriteRule ^blog-f1-visa\.html$ /blog-f1-visa [R=301,L,NC]
  RewriteRule ^blog-gre-gmat\.html$ /blog-gre-gmat [R=301,L,NC]
  RewriteRule ^blog-isat-story\.html$ /blog-isat-story [R=301,L,NC]
  RewriteRule ^blog-personal-statement\.html$ /blog-personal-statement [R=301,L,NC]
  RewriteRule ^blog-scholarships\.html$ /blog-scholarships [R=301,L,NC]
  RewriteRule ^blog-toronto\.html$ /blog-toronto [R=301,L,NC]
  RewriteRule ^blog-application-timeline\.html$ /blog-application-timeline [R=301,L,NC]
  RewriteRule ^blog-budgeting-abroad\.html$ /blog-budgeting-abroad [R=301,L,NC]
  RewriteRule ^blog-canada-study-permit\.html$ /blog-canada-study-permit [R=301,L,NC]
  RewriteRule ^blog-fully-funded-masters\.html$ /blog-fully-funded-masters [R=301,L,NC]
  RewriteRule ^blog-ielts-vs-toefl\.html$ /blog-ielts-vs-toefl [R=301,L,NC]
  RewriteRule ^blog-post-study-work\.html$ /blog-post-study-work [R=301,L,NC]
  RewriteRule ^blog-proof-of-funds\.html$ /blog-proof-of-funds [R=301,L,NC]
  RewriteRule ^blog-recommendation-letters\.html$ /blog-recommendation-letters [R=301,L,NC]
  RewriteRule ^blog-sat-prep-nigeria\.html$ /blog-sat-prep-nigeria [R=301,L,NC]
  RewriteRule ^blog-study-germany\.html$ /blog-study-germany [R=301,L,NC]
  RewriteRule ^blog-uk-student-visa\.html$ /blog-uk-student-visa [R=301,L,NC]
  RewriteRule ^blog-waec-international\.html$ /blog-waec-international [R=301,L,NC]
  RewriteRule ^blog\.html$ /blog [R=301,L,NC]
  RewriteRule ^consulting\.html$ /consulting [R=301,L,NC]
  RewriteRule ^contact\.html$ /contact [R=301,L,NC]
  RewriteRule ^disclaimer\.html$ /disclaimer [R=301,L,NC]
  RewriteRule ^faq\.html$ /faq [R=301,L,NC]
  RewriteRule ^how-it-works\.html$ /how-it-works [R=301,L,NC]
  RewriteRule ^partner\.html$ /partner [R=301,L,NC]
  RewriteRule ^pbc-eduaid\.html$ /pbc-eduaid [R=301,L,NC]
  RewriteRule ^pbc-isat\.html$ /pbc-isat [R=301,L,NC]
  RewriteRule ^privacy\.html$ /privacy-policy [R=301,L,NC]
  RewriteRule ^scholarship-guidance\.html$ /scholarship-guidance [R=301,L,NC]
  RewriteRule ^services\.html$ /services [R=301,L,NC]
  RewriteRule ^sitemap\.html$ /sitemap [R=301,L,NC]
  RewriteRule ^study-australia\.html$ /study-australia [R=301,L,NC]
  RewriteRule ^study-canada\.html$ /study-canada [R=301,L,NC]
  RewriteRule ^study-europa\.html$ /study-europa [R=301,L,NC]
  RewriteRule ^study-uk\.html$ /study-uk [R=301,L,NC]
  RewriteRule ^study-usa\.html$ /study-usa [R=301,L,NC]
  RewriteRule ^team\.html$ /team [R=301,L,NC]
  RewriteRule ^terms\.html$ /terms-and-conditions [R=301,L,NC]
  RewriteRule ^universities\.html$ /universities [R=301,L,NC]
  RewriteRule ^visa-counselling\.html$ /visa-counselling [R=301,L,NC]

  # ── Front controller: anything that isn't a real file/dir goes
  #    through index.php (clean routes, e.g. /about, /privacy-policy) ──
  #    EduAid and iSAT subsites have their own front controllers —
  #    skip them here so their own .htaccess handles routing.
  RewriteCond %{REQUEST_URI} !^/(eduaid|isat)/
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^ index.php [L]
</IfModule>

# ── HSTS + Security Headers ─────────────────────────────────
<IfModule mod_headers.c>
  Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
  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=()"
</IfModule>

# ── Gzip Compression (Page Speed) ───────────────────────────
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript application/json image/svg+xml
</IfModule>

# ── Browser Caching (Page Speed) ────────────────────────────
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/jpg "access plus 1 year"
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
  ExpiresByType text/html "access plus 0 seconds"
</IfModule>

# ── Block direct access to the /pages source folder ─────────
# (pages are only meant to be served through index.php)
<IfModule mod_rewrite.c>
  RewriteRule ^pages/ - [F,L]
</IfModule>

# ── Prevent directory listing ───────────────────────────────
Options -Indexes

# Custom 404 handled by index.php's front controller.
