# AR NUTRITION Wellness Directory — Hostinger / Apache clean URLs
Options -Indexes
DirectoryIndex index.php

<IfModule mod_authz_core.c>
  <FilesMatch "^(config\.php|config\.example\.php)$">
    Require all denied
  </FilesMatch>
</IfModule>

<IfModule mod_rewrite.c>
  RewriteEngine On

  # Never expose private application folders.
  RewriteRule ^(app|cron|database|includes|storage)(/|$) - [F,L,NC]

  # Canonicalise old /public/... URLs to the domain root.
  RewriteCond %{THE_REQUEST} \s/+public/([^\s?]*) [NC]
  RewriteRule ^public/(.*)$ /$1 [R=301,L,NE]

  # Remove index.php and .php from browser-visible URLs.
  RewriteCond %{THE_REQUEST} \s/+(.*/)?index\.php(?:[?\s]) [NC]
  RewriteRule ^(.*/)?index\.php$ /$1 [R=301,L]
  RewriteCond %{THE_REQUEST} \s/+(.+?)\.php(?:[?\s]) [NC]
  RewriteRule ^(.+)\.php$ /$1 [R=301,L]

  # Public assets live under public/assets.
  RewriteRule ^assets/(.*)$ public/assets/$1 [L]

  # Existing public directories (e.g. /admin and /professional).
  RewriteCond %{DOCUMENT_ROOT}/public/$1 -d
  RewriteRule ^(.+?)/?$ public/$1/ [L]

  # CMS pretty URLs: /page/about-us -> public/page.php?slug=about-us
  RewriteRule ^page/([a-z0-9]+(?:-[a-z0-9]+)*)/?$ public/page.php?slug=$1 [QSA,L,NC]

  # PHP routes without extensions, including nested admin/professional pages.
  RewriteCond %{DOCUMENT_ROOT}/public/$1.php -f
  RewriteRule ^(.+?)/?$ public/$1.php [L]

  # Real files already inside the public folder.
  RewriteCond %{DOCUMENT_ROOT}/public/$1 -f
  RewriteRule ^(.+)$ public/$1 [L]

  # Homepage.
  RewriteRule ^$ public/index.php [L]
</IfModule>
