# Fichier .htaccess pour StayManager - Production
# Version optimisée pour www.3cfri-ci.net/StayManager


# Activer le moteur de réécriture
RewriteEngine On

# Rediriger vers HTTPS (recommandé)
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Définir l'environnement de production
SetEnv APP_ENV production

# Page d'accueil - Redirection vers index.php si pas de fichier
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/StayManager/?$
RewriteRule ^$ index.php [L]

# Routes principales - Accès direct aux fichiers PHP
# Les fichiers PHP sont accessibles directement (pas de réécriture nécessaire)
# Exemples :
# - /StayManager/login.php
# - /StayManager/dashboard_dynamic.php
# - /StayManager/reservations.php?action=create
# - /StayManager/restaurant_orders.php?action=show&id=1
# - etc.

# Protéger les fichiers de configuration
<FilesMatch "^(database|config)\.production\.php$">
    Order allow,deny
    Deny from all
</FilesMatch>

# Protéger les fichiers sensibles
<FilesMatch "\.(log|sql|backup|env)$">
    Order allow,deny
    Deny from all
</FilesMatch>

# Protéger les dossiers sensibles
RedirectMatch 403 ^/StayManager/config/.*\.production\.php$
RedirectMatch 403 ^/StayManager/logs/.*
RedirectMatch 403 ^/StayManager/backups/.*
RedirectMatch 403 ^/StayManager/cache/.*
RedirectMatch 403 ^/StayManager/vendor/.*
RedirectMatch 403 ^/StayManager/database/.*\.sql$

# Désactiver l'affichage des répertoires
Options -Indexes

# Protection contre les injections
<IfModule mod_php7.c>
    php_flag display_errors Off
    php_flag log_errors On
    php_value error_log /home/jovi1068/public_html/StayManager/logs/php_errors.log
</IfModule>

<IfModule mod_php8.c>
    php_flag display_errors Off
    php_flag log_errors On
    php_value error_log /home/jovi1068/public_html/StayManager/logs/php_errors.log
</IfModule>

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

# Cache des fichiers statiques
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType application/pdf "access plus 1 month"
</IfModule>

# Headers de sécurité
<IfModule mod_headers.c>
    # Protection XSS
    Header set X-XSS-Protection "1; mode=block"
    # Protection contre le clickjacking
    Header set X-Frame-Options "SAMEORIGIN"
    # Protection MIME type sniffing
    Header set X-Content-Type-Options "nosniff"
    # Politique de référent
    Header set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>
