# BEGIN LSCACHE
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
<IfModule LiteSpeed>
  RewriteEngine on
  CacheLookup on

  RewriteRule .* - [E=Cache-Control:no-autoflush]
  RewriteRule litespeed/debug/.*\.log$ - [F,L]
  RewriteRule \.litespeed_conf\.dat - [F,L]

  # ASYNC support
  RewriteCond %{REQUEST_URI} /wp-admin/admin-ajax\.php
  RewriteCond %{QUERY_STRING} action=async_litespeed
  RewriteRule .* - [E=noabort:1]

  # MOBILE detection
  RewriteCond %{HTTP_USER_AGENT} Mobile|Android|Silk/|Kindle|BlackBerry|Opera\ Mini|Opera\ Mobi [NC]
  RewriteRule .* - [E=Cache-Control:vary=%{ENV:LSCACHE_VARY_VALUE}+ismobile]

  # CACHE RESOURCE optimization
  RewriteRule wp-content/.*/[^/]*(responsive|css|js|dynamic|loader|fonts)\.php - [E=cache-control:max-age=3600]

  # WEBP support
  RewriteCond %{HTTP_ACCEPT} "image/webp"
  RewriteRule .* - [E=Cache-Control:vary=%{ENV:LSCACHE_VARY_VALUE}+webp]

  RewriteCond %{HTTP_USER_AGENT} iPhone.*Version/(\d{2}).*Safari
  RewriteCond %1 >13
  RewriteRule .* - [E=Cache-Control:vary=%{ENV:LSCACHE_VARY_VALUE}+webp]

  RewriteCond %{HTTP_USER_AGENT} Firefox/([0-9]+)
  RewriteCond %1 >=65
  RewriteRule .* - [E=Cache-Control:vary=%{ENV:LSCACHE_VARY_VALUE}+webp]

  # DROPQS - strip tracking parameters
  CacheKeyModify -qs:fbclid
  CacheKeyModify -qs:gclid
  CacheKeyModify -qs:utm*
  CacheKeyModify -qs:_ga
</IfModule>
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
# END LSCACHE

# BEGIN NON_LSCACHE
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
<IfModule mod_expires.c>
  ExpiresActive on

  # Images - Reduced cache time to prevent issues
  ExpiresByType image/x-icon A86400
  ExpiresByType image/vnd.microsoft.icon A86400
  ExpiresByType image/svg+xml A86400
  ExpiresByType image/jpg A86400
  ExpiresByType image/jpeg A86400
  ExpiresByType image/png A86400
  ExpiresByType image/gif A86400
  ExpiresByType image/webp A86400
  ExpiresByType image/avif A86400

  # Media
  ExpiresByType video/ogg A31557600
  ExpiresByType audio/ogg A31557600
  ExpiresByType video/mp4 A31557600
  ExpiresByType video/webm A31557600
  ExpiresByType video/quicktime A31557600

  # CSS and JS
  ExpiresByType text/css A31557600
  ExpiresByType text/javascript A31557600
  ExpiresByType application/javascript A31557600
  ExpiresByType application/x-javascript A31557600

  # Fonts
  ExpiresByType application/x-font-ttf A31557600
  ExpiresByType application/x-font-woff A31557600
  ExpiresByType application/font-woff A31557600
  ExpiresByType application/font-woff2 A31557600
  ExpiresByType application/vnd.ms-fontobject A31557600
  ExpiresByType font/ttf A31557600
  ExpiresByType font/otf A31557600
  ExpiresByType font/woff A31557600
  ExpiresByType font/woff2 A31557600

  # Documents
  ExpiresByType application/pdf A31557600
</IfModule>
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
# END NON_LSCACHE

# BEGIN PHP Upload Configuration for 100+ Files (no restriction on time — avoid "unable to connect")
<IfModule mod_php.c>
  php_value max_file_uploads 150
  php_value upload_max_filesize 50M
  php_value post_max_size 1000M
  php_value max_input_time 600
  php_value max_execution_time 0
  php_value memory_limit 512M
  php_value max_input_vars 3000
</IfModule>
# END PHP Upload Configuration

# BEGIN Modified Image Cache Rules (Less Aggressive)
<IfModule mod_headers.c>
  # Only apply no-cache to temp upload directory
  <LocationMatch "^/api/uploads/temp/">
    Header always set Cache-Control "no-store, no-cache, must-revalidate, max-age=0"
    Header always set Pragma "no-cache"
    Header always set Expires "Thu, 01 Jan 1970 00:00:00 GMT"
    Header always unset ETag
    Header always unset Last-Modified
  </LocationMatch>
</IfModule>

<IfModule LiteSpeed>
  <Location "/api/uploads/temp/">
    CacheDisable on
  </Location>
</IfModule>

<IfModule mod_rewrite.c>
  RewriteCond %{REQUEST_URI} ^/api/uploads/temp/.*\.(jpg|jpeg|png|gif|webp|avif|svg|ico|bmp|tiff)$ [NC]
  RewriteRule .* - [E=Cache-Control:no-store,E=no-cache:1]
</IfModule>
# END Modified Image Cache Rules

# BEGIN WebP Rewrite
<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteCond %{HTTP_ACCEPT} image/webp
  RewriteCond %{REQUEST_FILENAME} \.(jpe?g|png)$ [NC]
  RewriteCond %{REQUEST_FILENAME}.webp -f
  RewriteCond %{QUERY_STRING} !no_webp
  RewriteRule ^(.+)\.(jpe?g|png)$ $1.$2.webp [T=image/webp,E=webp,L]
</IfModule>

<IfModule mod_mime.c>
  AddType image/webp .webp
</IfModule>
# END WebP Rewrite

# BEGIN Hotlink Protection (Modified - Less Restrictive)
# COMMENTED OUT FOR TESTING - Remove # to re-enable after testing
# <IfModule mod_rewrite.c>
#   RewriteCond %{HTTP_REFERER} !^$
#   RewriteCond %{HTTP_REFERER} !^https?://(www\.)?(api\.freeblis\.com|tyfm\.org|freeblis\.com|localhost)(/.*)?$ [NC]
#   RewriteCond %{REQUEST_URI} !^/api/uploads/temp/
#   RewriteRule \.(jpg|jpeg|gif|png|bmp|mp4|mov|webm|avi|ogv)$ - [F,NC]
# </IfModule>
# END Hotlink Protection

# BEGIN Custom API Rewrites
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteRule ^loginfunction$ /api/loginfunction.php [L]
  RewriteRule ^rewardshistory$ /api/rewardshistory.php [L]
  RewriteRule ^productmanagement$ /api/productmanagement.php [L]
  RewriteRule ^wishlist$ /api/wishlist.php [L]
  RewriteRule ^bevendor$ /api/bevendor.php [L]
  RewriteRule ^feedback$ /api/feedback.php [L]
  RewriteRule ^videoads$ /api/videoads.php [L]
  RewriteRule ^submitdoc /api/submitdoc.php [L]
#   RewriteRule ^studentdoc /api/studentdoc.php [L]
  RewriteRule ^chatapi /api/chat_api.php [L]
  RewriteRule ^campaign /api/campaign.php [L]
  RewriteRule ^submitbsn /api/submitbsn.php [L]
  
  RewriteRule ^studentdoc_johor_pasirgudang/?$ /api/uitm/studentdoc_johor_pasirgudang.php [L]
  RewriteRule ^studentdoc_johor_segamat/?$ /api/uitm/studentdoc_johor_segamat.php [L]
  RewriteRule ^studentdoc_kedah_sungaipetani/?$ /api/uitm/studentdoc_kedah_sungaipetani.php [L]
  RewriteRule ^studentdoc_kelantanmachang/?$ /api/uitm/studentdoc_kelantanmachang.php [L]
  RewriteRule ^studentdoc_melaka_alorgajar/?$ /api/uitm/studentdoc_melaka_alorgajar.php [L]
  RewriteRule ^studentdoc_pahang_jengka/?$ /api/uitm/studentdoc_pahang_jengka.php [L]
  RewriteRule ^studentdoc_perak_sriiskandar/?$ /api/uitm/studentdoc_perak_sriiskandar.php [L]
  RewriteRule ^studentdoc_perak_tapah/?$ /api/uitm/studentdoc_perak_tapah.php [L]
  RewriteRule ^studentdoc_perlis_arau/?$ /api/uitm/studentdoc_perlis_arau.php [L]
  RewriteRule ^studentdoc_pulaupinang_pauh/?$ /api/uitm/studentdoc_pulaupinang_puah.php [L]
  RewriteRule ^studentdoc_sabah_kotakinabalu/?$ /api/uitm/studentdoc_sabah_kotakinabalu.php [L]
  RewriteRule ^studentdoc_sarawak_samarahan/?$ /api/uitm/studentdoc_sarawak_samarahan.php [L]
  RewriteRule ^studentdoc_sarawak_samarahan2/?$ /api/uitm/studentdoc_sarawak_samarahan2.php [L]
  RewriteRule ^studentdoc_selangor_puncakalam/?$ /api/uitm/studentdoc_selangor_puncakalam.php [L]
  RewriteRule ^studentdoc_shahalam/?$ /api/uitm/studentdoc_shahalam.php [L]
  RewriteRule ^studentdoc_terengganu_dungun/?$ /api/uitm/studentdoc_terengganu_dungun.php [L]
  RewriteRule ^studentdoc_kelantan_kotabahru/?$ /api/uitm/studentdoc_kelantan_kota_bahru.php [L]
  RewriteRule ^studentdoc_melaka_bandarmelaka/?$ /api/uitm/studentdoc_melaka_bandar_melaka.php [L]
  RewriteRule ^studentdoc_melaka_jasin/?$ /api/uitm/studentdoc_melaka_jasin.php [L]
  RewriteRule ^studentdoc_negerisembilan_kualapilah/?$ /api/uitm/studentdoc_negeri_sembilan_kuala_pilah.php [L]
  RewriteRule ^studentdoc_negerisembilan_rembau/?$ /api/uitm/studentdoc_negeri_sembilan_rembau.php [L]
  RewriteRule ^studentdoc_negerisembilan_seremban/?$ /api/uitm/studentdoc_negeri_sembilan_seremban.php [L]
  RewriteRule ^studentdoc_pahang_raub/?$ /api/uitm/studentdoc_pahang_raub.php [L]
  RewriteRule ^studentdoc_pulaupinang_bertam/?$ /api/uitm/studentdoc_pulau_pinang_bertam.php [L]
  RewriteRule ^studentdoc_selangor_sungaibuloh/?$ /api/uitm/studentdoc_selangor_sungaibuloh.php [L]
  RewriteRule ^studentdoc_terengganu_bukitbesi/?$ /api/uitm/studentdoc_terengganu_bukit_besi.php [L]
  RewriteRule ^studentdoc_terengganu_kualaterengganu/?$ /api/uitm/studentdoc_terengganu_kuala_terengganu.php [L]
  RewriteRule ^studentdoc_sarawak_mukah/?$ /api/uitm/studentdoc_sarawak_mukah.php [L]

  # ── ENS Smart Solution API Routes ────────────────────────────────────────

  # Auth
  RewriteRule ^auth_register/?$          /api/ensphp/api/ensphp/auth/register.php          [L]
  RewriteRule ^auth_login/?$             /api/ensphp/api/ensphp/auth/login.php              [L]
  RewriteRule ^auth_forgot_password/?$   /api/ensphp/api/ensphp/auth/forgot-password.php   [L]
  RewriteRule ^auth_change_password/?$   /api/ensphp/api/ensphp/auth/change-password.php   [L]

  # Public lookup (insurance codes, brand models, reviews)
  RewriteRule ^insurance_codes/?$        /api/ensphp/api/ensphp/insurance_codes.php         [L]
  RewriteRule ^brand_models/?$           /api/ensphp/api/ensphp/brand_models.php            [L]
  RewriteRule ^reviews/?$                /api/ensphp/api/ensphp/reviews.php                 [L]

  # Warranty
  RewriteRule ^warranty/?$               /api/ensphp/api/ensphp/warranty/index.php          [L]
  RewriteRule ^warranty_get/?$           /api/ensphp/api/ensphp/warranty/get.php            [L]

  # Claim
  RewriteRule ^claim/?$                  /api/ensphp/api/ensphp/claim/index.php             [L]

  # Dashboard
  RewriteRule ^dashboard_stats/?$        /api/ensphp/api/ensphp/dashboard/stats.php         [L]

  # Upload
  RewriteRule ^upload/?$                 /api/ensphp/api/ensphp/upload.php                  [L]

  # Admin – general
  RewriteRule ^admin_stats/?$            /api/ensphp/api/ensphp/admin/stats.php             [L]
  RewriteRule ^admin_approvals/?$        /api/ensphp/api/ensphp/admin/approvals.php         [L]
  RewriteRule ^admin_approve/?$          /api/ensphp/api/ensphp/admin/approve.php           [L]
  RewriteRule ^admin_reject/?$           /api/ensphp/api/ensphp/admin/reject.php            [L]
  RewriteRule ^admin_void/?$             /api/ensphp/api/ensphp/admin/void.php              [L]
  RewriteRule ^admin_reports/?$          /api/ensphp/api/ensphp/admin/reports.php           [L]
  RewriteRule ^admin_users/?$            /api/ensphp/api/ensphp/admin/users.php             [L]
  RewriteRule ^admin_create_user/?$      /api/ensphp/api/ensphp/admin/create-user.php       [L]
  RewriteRule ^admin_diagnostic/?$       /api/ensphp/api/ensphp/admin/diagnostic.php        [L]

  # Admin – password resets
  RewriteRule ^admin_password_resets/?$  /api/ensphp/api/ensphp/admin/password-resets.php  [L]
  RewriteRule ^admin_reset_password/?$   /api/ensphp/api/ensphp/admin/reset-password.php   [L]
  RewriteRule ^admin_reject_reset/?$     /api/ensphp/api/ensphp/admin/reject-reset.php      [L]

  # Admin – setup (insurance codes, brand models)
  RewriteRule ^admin_insurance_codes/?$  /api/ensphp/api/ensphp/admin/insurance_codes.php  [L]
  RewriteRule ^admin_brand_models/?$     /api/ensphp/api/ensphp/admin/brand_models.php      [L]

  # Admin – reviews
  RewriteRule ^admin_reviews/?$          /api/ensphp/api/ensphp/admin/reviews.php           [L]

</IfModule>
# END Custom API Rewrites

# BEGIN PHP Version Handler
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php81 .php .php8 .phtml
</IfModule>
# END PHP Version Handler

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php81” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php81 .php .php8 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
