php_value date.timezone Asia/Bangkok

Options +SymLinksIfOwnerMatch
RewriteEngine On

# 503 for site maintenance
#ErrorDocument 503 /503.html
#RewriteCond %{REQUEST_URI}% !^/503\.html [NC]
#RewriteRule ^ - [R=503,L]

# 1. บล็อกการเข้าถึงไฟล์ระบบ Laravel เพื่อความปลอดภัยสูงสุด
RewriteRule ^(\.env|composer\.(json|lock)|package\.(json|lock)|phpunit\.xml|README\.md|server\.php) - [F,L,NC]
RewriteRule ^(app|bootstrap/cache|config|database|resources|routes|storage|tests|vendor)/ - [F,L,NC]

# Force HTTPS (Redirect http:// to https://)
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

# Redirect www to non-www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/index\.php [NC]
RewriteRule ^index\.php$ / [R=301,L]
##################################

# Allow Installatron requests (keep this if needed)
RewriteCond %{REQUEST_FILENAME} deleteme\.\w+\.php
RewriteRule (.*) - [L]

# ---------------------------------------------------
# [ปรับปรุงใหม่] 2. ค้นหาไฟล์ทุกชนิดจากโฟลเดอร์ /public อัตโนมัติ
# (รองรับ robots.txt, ads.txt, sitemap, img, css ฯลฯ ครอบคลุมทั้งหมด)
# ---------------------------------------------------
RewriteCond %{REQUEST_URI} !^/public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ public/$1 [L]

# ---------------------------------------------------
# 3. Handle Laravel URLs Properly (ถ้าหาไฟล์ใน public ไม่เจอ ค่อยรันหน้าเว็บ)
# ---------------------------------------------------
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

# One year for image files
<filesMatch "\.(jpg|jpeg|png|gif|ico|svg)$">
Header set Cache-Control "max-age=31536000, public"
</filesMatch>
# One month for css and js
<filesMatch "\.(css|js)$">
Header set Cache-Control "max-age=2628000, public"
</filesMatch>