Options -Indexes
RewriteEngine On

# 1. Force HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://topdigitalmarketingcompanies.in/$1 [R=301,L]



RewriteCond %{REQUEST_URI} !^/insights/page/ [NC]
RewriteCond %{REQUEST_URI} !^/product-category/([^/]+)/page/ [NC]

# 2. Remove Trailing Slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=301,L]

# 3. Prevent access to internal folders
RewriteRule ^(assets|includes|data|uploads)(/.*)?$ - [L]

# 4. Specific Mappings
RewriteRule ^$ router.php?page=home [L,QSA]
RewriteRule ^(about|contact|manufacturing|global-presence|employment)/?$ router.php?page=$1 [L,QSA]
RewriteRule ^products/?$ router.php?page=products-list [L,QSA]
RewriteRule ^insights/page/([0-9]+)/?$ router.php?page=blog-all&p=$1 [L,QSA]
RewriteRule ^insights/?$ router.php?page=blog-all [L,QSA]


# NEW: Category Pagination Rule (Catches category page numbers before generic sub-categories)
RewriteRule ^product-category/([^/]+)/page/([0-9]+)/?$ router.php?page=category&cat=$1&p=$2 [L,QSA]

# 5. Dynamic Mappings
RewriteRule ^product-category/([^/]+)/([^/]+)/?$ router.php?page=category&cat=$1&therapy=$2 [L,QSA]
RewriteRule ^product-category/([^/]+)/?$ router.php?page=category&cat=$1 [L,QSA]
RewriteRule ^therapeutic/([^/]+)/?$ router.php?page=therapeutic&therapy=$1 [L,QSA]
RewriteRule ^product/([^/]+)/?$ router.php?page=product-single&slug=$1 [L,QSA]

# 6. Catch-all for Blogs
RewriteRule ^([a-zA-Z0-9-]+)/?$ router.php?page=blog-single&slug=$1 [L,QSA]

# 7. Fallback for 404
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ router.php?page=404 [L,QSA]


<IfModule mod_expires.c>

ExpiresActive On

ExpiresByType image/webp "access plus 1 year"
ExpiresByType image/avif "access plus 1 year"

ExpiresByType text/css "access plus 1 year"

ExpiresByType application/javascript "access plus 1 year"

ExpiresByType font/woff2 "access plus 1 year"

</IfModule>

<IfModule mod_expires.c>
  ExpiresActive On

  ExpiresByType image/avif "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"

  ExpiresByType font/woff2 "access plus 1 year"

  ExpiresByType text/css "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
</IfModule>

<IfModule mod_headers.c>
  <FilesMatch "\.(avif|webp|png|jpg|jpeg|svg|woff2)$">
    Header set Cache-Control "public, max-age=31536000, immutable"
  </FilesMatch>

  <FilesMatch "\.(css|js)$">
    Header set Cache-Control "public, max-age=2592000"
  </FilesMatch>
</IfModule>
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php82” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php82 .php .php8 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
