# ============================================
# .htaccess for Euro Store
# ============================================

# Enable rewrite engine
RewriteEngine On

# Do not list folders if directory browsing is enabled by the host.
Options -Indexes

# One-time setup utilities and private application files must never be served.
# These rules are relative to this installation folder, so they work at /asap
# and when the store is moved to the web root.
RewriteRule ^(?:import_products\.php|database(?:/|$)|app(?:/|$)|storage(?:/|$)|includes(?:/|$)) - [F,L,NC]

# Public, language-specific storefront URLs. The language code is passed to
# PHP, while the customer and search engine keep the clean /de/shop/ URL.
RewriteRule ^([a-z]{2}(?:-[a-z]{2})?)/(shop|order|payment|manual-payment|automatic-payment|payment-pending|success|contact)/?$ $2.php?lang=$1 [QSA,L,NC]
RewriteRule ^shop/?$ shop.php [QSA,L,NC]

# ============================================
# FIX: Pass REQUEST_URI to PHP
# ============================================

# For files that don't exist, redirect to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]

# Set environment variable for REQUEST_URI
RewriteRule .* - [E=REQUEST_URI:%{REQUEST_URI}]

# ============================================
# SECURITY
# ============================================

# Block access to sensitive files
<FilesMatch "^(config\.php|\.env|\.htaccess|\.htpasswd|composer\.(json|lock)|.*\.sql)$">
    Require all denied
</FilesMatch>

# ============================================
# PERFORMANCE
# ============================================

# Enable GZIP compression
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript application/json
</IfModule>

# Browser caching
<IfModule mod_expires.c>
    ExpiresActive On
    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 text/css "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
</IfModule>

# ============================================
# ERROR PAGES
# ============================================

ErrorDocument 404 /asap/404.php
ErrorDocument 403 /asap/403.php
ErrorDocument 500 /asap/500.php
