RewriteEngine On

# Redirection des .html
RewriteCond %{THE_REQUEST} \s/+(.*?/)?(?:index)?(.*?)\.html[\s?/] [NC]
RewriteRule ^ /%1%2 [R=302,L,NE]

# Redirection waitlist
RedirectMatch 301 ^/waitlist/?(.*)$ https://idsma.imators.com

# Gestion des extensions .html et .php
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ $1.html [L]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

# Forcer HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Compression DEFLATE
<IfModule mod_deflate.c>
    # Compression standard
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    
    # Compression des images
    AddOutputFilterByType DEFLATE image/png
    AddOutputFilterByType DEFLATE image/webp
    
    # Niveau de compression optimal
    DeflateCompressionLevel 6
</IfModule>

# Gestion du cache
<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 image/webp "access plus 1 year"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/pdf "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType text/javascript "access plus 1 month"
    ExpiresByType text/html "access plus 600 seconds"
    ExpiresByType application/x-shockwave-flash "access plus 1 month"
</IfModule>

# Headers et sécurité
<IfModule mod_headers.c>
    # Cache Control
    <FilesMatch "\.(html|htm|js|css)$">
        Header set Cache-Control "max-age=600, public"
    </FilesMatch>

    # Keep-Alive et compression
    Header set Connection keep-alive
    Header append Vary Accept-Encoding

    # Security Headers
    Header set X-Content-Type-Options "nosniff"
    Header set X-XSS-Protection "1; mode=block"
    Header set X-Frame-Options "SAMEORIGIN"
    Header always set Referrer-Policy "no-referrer-when-downgrade"
    Header set Content-Security-Policy "default-src 'self' https:; script-src 'self' 'unsafe-inline' 'unsafe-eval' https:; style-src 'self' 'unsafe-inline' https:; img-src 'self' data: https:; font-src 'self' https:; frame-src 'none'; object-src 'none'; connect-src 'self' https:"
</IfModule>

# Redirection des erreurs
ErrorDocument 404 /404.shtml
ErrorDocument 500 /.html

# Redirection HTTPS pour imators.com
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteCond %{HTTP_HOST} ^imators\.com$
RewriteRule ^/?$ "https\:\/\/imators\.com\/" [R=301,L]

<Files 403.shtml>
order allow,deny
allow from all
</Files>

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php81” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php81 .php .php8 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
