# ---------------------------------------------------------------
# DigiGlobal — URL routing (Apache / cPanel)
# All pages are generated by index.php from data/pages/*.json
# ---------------------------------------------------------------
DirectoryIndex index.php
Options -Indexes

<IfModule mod_rewrite.c>
RewriteEngine On

# Force HTTPS (comment out if your hosting has no SSL yet)
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTP_HOST} !^(localhost|127\.0\.0\.1)(:\d+)?$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Home page aliases
RewriteRule ^index\.html$ index.php [L]

# Page URLs like /sell-gold-for-cash-in-jayanagar/  (and old .html links)
RewriteRule ^([A-Za-z0-9_-]+)\.html$ index.php?slug=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9_-]+)/?$ index.php?slug=$1 [L,QSA]
# Anything else that doesn't exist (e.g. old WordPress paths) → 404 page / redirects
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(wp-content|wp-includes|wp-admin|category|tag|author)/ - [G,L]
</IfModule>

# Block direct access to private folders and files
<IfModule mod_rewrite.c>
RewriteRule ^(data|inc)(/|$) - [F,L]
</IfModule>
<FilesMatch "\.(sqlite|sqlite-wal|sqlite-shm|json|log|tmp|md)$">
  <IfModule mod_authz_core.c>
    Require all denied
  </IfModule>
  <IfModule !mod_authz_core.c>
    Order allow,deny
    Deny from all
  </IfModule>
</FilesMatch>

<Files "error_log">
  <IfModule mod_authz_core.c>
    Require all denied
  </IfModule>
</Files>

# Caching for static assets
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css "access plus 30 days"
ExpiresByType application/javascript "access plus 30 days"
ExpiresByType image/png "access plus 90 days"
ExpiresByType image/jpeg "access plus 90 days"
ExpiresByType image/webp "access plus 90 days"
ExpiresByType image/svg+xml "access plus 90 days"
</IfModule>
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/css application/javascript application/json image/svg+xml text/plain application/xml
</IfModule>
