# Antalya Restaurant - Apache Configuration
# FIXED - Handles Next.js static export with trailing slashes 100%

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # Prevent directory listing and disable MultiViews (Critical for Next.js)
    Options -Indexes
    Options +FollowSymLinks
    Options -MultiViews

    # 1. Custom 404 handling
    ErrorDocument 404 /404.html

    # 2. Handle trailing slashes strictly
    # If request is a file, serve it directly
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ - [L]

    # If request is a directory, serve the index.html inside it
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^(.*[^/])$ $1/ [R=301,L]

    # Rewrite all folder requests to their index.html
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^(.*)/$ $1/index.html [L]

    # 4. Fallback for clean URLs (if folder detection fails but index.html exists)
    RewriteCond %{DOCUMENT_ROOT}/$1/index.html -f
    RewriteRule ^(.*)/$ $1/index.html [L]

    # 4. Fallback for clean URLs (just in case)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteRule ^(.*)$ $1.html [L]
</IfModule>

# Security Headers
<IfModule mod_headers.c>
    Header set X-Content-Type-Options "nosniff"
    Header set X-Frame-Options "DENY"
    Header set X-XSS-Protection "1; mode=block"
    Header set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

# Cache Control
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault "access plus 1 month"
    ExpiresByType text/html "access plus 0 seconds"
    ExpiresByType text/xml "access plus 0 seconds"
    ExpiresByType application/xml "access plus 0 seconds"
    ExpiresByType application/json "access plus 0 seconds"
    ExpiresByType image/jpg "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/webp "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"
    ExpiresByType image/x-icon "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 year"
    ExpiresByType text/css "access plus 1 year"
</IfModule>
