RewriteEngine On
RewriteBase /

# ----------------------------------
# 0. EXCLUDE ADMIN (VERY IMPORTANT)
# ----------------------------------
RewriteRule ^admin(/.*)?$ - [L]

# ----------------------------------
# 1. Force HTTPS + non-www (PUBLIC SITE ONLY)
# ----------------------------------
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} ^www\.jaybalajiassociates\.com$ [NC]
RewriteRule ^(.*)$ https://jaybalajiassociates.com/$1 [L,R=301]

# ----------------------------------
# 2. Remove index.php (PUBLIC SITE ONLY)
# ----------------------------------
RewriteRule ^index\.php$ https://jaybalajiassociates.com/ [L,R=301]

# ----------------------------------
# 3. Redirect .php URLs to clean URLs
# ----------------------------------
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ %1 [L,R=301]

# ----------------------------------
# Static pages
# ----------------------------------
RewriteRule ^about/?$ about.php [L]
RewriteRule ^gallery/?$ gallery.php [L]
RewriteRule ^contact/?$ contact.php [L]

# ----------------------------------
# Special product category redirects
# ----------------------------------
# RewriteRule ^products/solar-water-heater/?$ solar-water-heater.php [L,QSA]
# RewriteRule ^products/solar-water-pump/?$ solar-water-pump.php [L,QSA]

# ----------------------------------
# Product category
# ----------------------------------
RewriteRule ^products/([^/]+)/?$ products.php [L,QSA]

# ----------------------------------
# Single product
# ----------------------------------
RewriteRule ^product/([^/]+)/?$ product-detail.php [L,QSA]

# ----------------------------------
# Products listing
# ----------------------------------
RewriteRule ^products/?$ product-categories.php [L,QSA]

# ----------------------------------
# Services
# ----------------------------------
RewriteRule ^services/?$ services-list.php [L,QSA]
RewriteRule ^services/([^/]+)/?$ service.php [L,QSA]

# ----------------------------------
# Solutions
# ----------------------------------
RewriteRule ^solutions/([^/]+)/?$ solution.php [L,QSA]
# ----------------------------------
# Blog listing
# ----------------------------------
RewriteRule ^blogs/?$ blogs.php [L,QSA]

# ----------------------------------
# Blog
# ----------------------------------
RewriteRule ^blog/([^/]+)/?$ blog-detail.php [L,QSA]

# ----------------------------------
# Location
# ----------------------------------
RewriteRule ^location/?$ locations.php [L,QSA]
RewriteRule ^location/([^/]+)/?$ location.php?slug=$1 [L,QSA]

RewriteRule ^form-process/?$ form-process.php [L]

RewriteRule ^about2/?$ about2.php [L]

# ----------------------------------
# Custom 404
# ----------------------------------
ErrorDocument 404 /404.php
