# SilverCare Plus - Apache config
Options -Indexes
ServerSignature Off

# Block access to sensitive directories
RedirectMatch 403 /\.git
RedirectMatch 403 /config/
RedirectMatch 403 /install/
RedirectMatch 403 /includes/

# Block access to sensitive files
<FilesMatch "\.(env|sql|log|md|json|lock)$">
  Require all denied
</FilesMatch>

# Force UTF-8
AddDefaultCharset UTF-8

# Gzip compression
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript application/json text/xml application/xml
</IfModule>

# Browser caching
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/jpg "access plus 1 month"
  ExpiresByType image/jpeg "access plus 1 month"
  ExpiresByType image/png "access plus 1 month"
  ExpiresByType image/webp "access plus 1 month"
  ExpiresByType image/svg+xml "access plus 1 month"
  ExpiresByType text/css "access plus 1 week"
  ExpiresByType application/javascript "access plus 1 week"
  ExpiresByType image/x-icon "access plus 1 year"
</IfModule>

# Security headers
<IfModule mod_headers.c>
  Header set X-Content-Type-Options "nosniff"
  Header set X-Frame-Options "SAMEORIGIN"
  Header set Referrer-Policy "strict-origin-when-cross-origin"
  Header set X-XSS-Protection "1; mode=block"
</IfModule>

# Pretty URLs — slug-based routing on the main domain
<IfModule mod_rewrite.c>
  RewriteEngine On
  # If the site lives in a subfolder, set RewriteBase accordingly (e.g. /senior-portal/)
  # RewriteBase /

  # Redirect /admin to /admin/
  RewriteRule ^admin$ admin/ [L,R=301]

  # Never rewrite real files or directories (assets, admin, api, install…)
  RewriteCond %{REQUEST_FILENAME} -f [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^ - [L]

  # XML sitemap
  RewriteRule ^sitemap\.xml$ sitemap.php [L]

  # Slug routes -> single router (view.php). QSA keeps any query string.
  RewriteRule ^coupon/([A-Za-z0-9_-]+)/?$   view.php?type=coupon&slug=$1   [L,QSA]
  RewriteRule ^brand/([A-Za-z0-9_-]+)/?$     view.php?type=brand&slug=$1    [L,QSA]
  RewriteRule ^category/([A-Za-z0-9_-]+)/?$  view.php?type=category&slug=$1 [L,QSA]
  RewriteRule ^page/([A-Za-z0-9_-]+)/?$      view.php?type=page&slug=$1     [L,QSA]
</IfModule>

# Force HTTPS (uncomment after SSL setup)
# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
