# .htaccess für LMX Trade - SEO & Performance Optimierung
# Erstellt: 7. Dezember 2025

# ===================================
# 1. HTTPS Erzwingen (falls SSL verfügbar)
# ===================================
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTPS} off
  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

# ===================================
# 2. WWW zu Non-WWW (oder umgekehrt)
# ===================================
# Auskommentieren, falls gewünscht:
# RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
# RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

# ===================================
# 3. GZIP Kompression aktivieren
# ===================================
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/x-javascript application/json application/xml
  AddOutputFilterByType DEFLATE image/svg+xml
</IfModule>

# ===================================
# 4. Browser Caching
# ===================================
<IfModule mod_expires.c>
  ExpiresActive On
  
  # Bilder (1 Woche - können bei Änderungen schneller aktualisiert werden)
  ExpiresByType image/jpg "access plus 1 week"
  ExpiresByType image/jpeg "access plus 1 week"
  ExpiresByType image/gif "access plus 1 week"
  ExpiresByType image/png "access plus 1 week"
  ExpiresByType image/webp "access plus 1 week"
  ExpiresByType image/svg+xml "access plus 1 week"
  ExpiresByType image/x-icon "access plus 1 month"
  
  # CSS, JavaScript (1 Tag - für häufige Updates)
  ExpiresByType text/css "access plus 1 day"
  ExpiresByType application/javascript "access plus 1 day"
  ExpiresByType text/javascript "access plus 1 day"
  
  # Fonts (1 Monat - ändern sich selten)
  ExpiresByType font/woff "access plus 1 month"
  ExpiresByType font/woff2 "access plus 1 month"
  ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
  ExpiresByType font/ttf "access plus 1 month"
  ExpiresByType font/otf "access plus 1 month"
  
  # HTML (kein Cache - immer aktuell)
  ExpiresByType text/html "access plus 0 seconds"
  
  # PDF (1 Woche)
  ExpiresByType application/pdf "access plus 1 week"
</IfModule>

# ===================================
# 5. Cache-Control Headers
# ===================================
<IfModule mod_headers.c>
  # Statische Ressourcen cachen (1 Woche für Bilder, 1 Monat für Fonts)
  <FilesMatch "\.(jpg|jpeg|png|gif|webp|svg|ico)$">
    Header set Cache-Control "max-age=604800, public"
  </FilesMatch>
  
  <FilesMatch "\.(css|js)$">
    Header set Cache-Control "max-age=86400, public"
  </FilesMatch>
  
  <FilesMatch "\.(woff|woff2|ttf|otf|eot)$">
    Header set Cache-Control "max-age=2592000, public"
  </FilesMatch>
  
  # HTML nicht cachen
  <FilesMatch "\.(html|htm|php)$">
    Header set Cache-Control "no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires 0
  </FilesMatch>
  
  # Security Headers
  Header set X-Content-Type-Options "nosniff"
  Header set X-Frame-Options "SAMEORIGIN"
  Header set X-XSS-Protection "1; mode=block"
  Header set Referrer-Policy "strict-origin-when-cross-origin"
  
  # Entferne Server-Signatur (falls möglich)
  Header unset Server
  Header unset X-Powered-By
</IfModule>

# ===================================
# 6. PHP-Einstellungen optimieren
# ===================================
<IfModule mod_php7.c>
  php_value upload_max_filesize 10M
  php_value post_max_size 10M
  php_value max_execution_time 300
  php_value max_input_time 300
</IfModule>

# ===================================
# 7. Verzeichnis-Listing deaktivieren
# ===================================
Options -Indexes

# ===================================
# 8. Custom Error Pages (optional)
# ===================================
# ErrorDocument 404 /404.html
# ErrorDocument 500 /500.html

# ===================================
# 9. Datei-Zugriff einschränken
# ===================================
<FilesMatch "^(composer\.json|composer\.lock|package\.json|\.git.*|\.env|config\.php)$">
  Order allow,deny
  Deny from all
</FilesMatch>

# ===================================
# 10. Clean URLs / URL Rewriting
# ===================================
<IfModule mod_rewrite.c>
  RewriteEngine On
  
  # Haupt-Domain auf index.php umleiten (falls direkt aufgerufen)
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} ^/$
  RewriteRule ^(.*)$ index.php [L]
</IfModule>

# ===================================
# 11. Content-Type für bestimmte Dateien
# ===================================
<IfModule mod_mime.c>
  AddType application/javascript js
  AddType text/css css
  AddType image/svg+xml svg svgz
  AddEncoding gzip svgz
  AddType font/woff woff
  AddType font/woff2 woff2
  AddType application/vnd.ms-fontobject eot
  AddType font/ttf ttf
  AddType font/otf otf
  AddType image/webp webp
</IfModule>

# ===================================
# 12. UTF-8 Encoding
# ===================================
AddDefaultCharset UTF-8
AddCharset UTF-8 .html .css .js .xml .json .rss .atom

# ===================================
# 13. ETag deaktivieren (optional)
# ===================================
<IfModule mod_headers.c>
  Header unset ETag
</IfModule>
FileETag None
