# ------------------------------------------------------------------------------
# Taco & Grill - Apache / cPanel / PHP Server Configuration
# ------------------------------------------------------------------------------

# 1. Default index file
DirectoryIndex index.php index.html

# 2. Enable Rewrite Engine
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # Redirect /deals.html to /deals (or deals.php)
    RewriteRule ^deals\.html$ /deals [R=301,L]

    # Serve clean URLs mapped to .php files if they exist (e.g. /menu -> menu.php)
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*)$ $1.php [L]

    # If the requested file or directory exists, serve it directly
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]

    # Otherwise send all requests to index.php (SPA & route fallback)
    RewriteRule ^.*$ index.php [NC,L]
</IfModule>

# 3. Modern MIME Types
<IfModule mod_mime.c>
    AddType image/avif .avif
    AddType image/webp .webp
    AddType image/svg+xml .svg .svgz
    AddType application/json .json
    AddType text/javascript .js .mjs
</IfModule>

# 4. Gzip / Deflate Compression
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json application/xml
</IfModule>

# 5. Browser Caching
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/webp "access plus 1 month"
    ExpiresByType image/avif "access plus 1 month"
    ExpiresByType image/svg+xml "access plus 1 month"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType text/javascript "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType application/json "access plus 0 seconds"
</IfModule>

# 6. Security & Cache Headers
<IfModule mod_headers.c>
    Header set X-Content-Type-Options "nosniff"
    Header set X-XSS-Protection "1; mode=block"
    Header set X-Frame-Options "SAMEORIGIN"

    # Ensure JSON data is never cached by browsers, CDN, or LiteSpeed
    <FilesMatch "\.(json)$">
        Header set Cache-Control "no-cache, no-store, must-revalidate, max-age=0"
        Header set Pragma "no-cache"
        Header set Expires "0"
    </FilesMatch>
</IfModule>
