< Alle Themen

Die perfekte WooCommerce .htaccess

Mit einer .htaccess Datei kann man viele Sicherheitsmaßnahmen von WordPress bzw. WooCommerce steuern. Doch die Datei kann noch viel mehr – außer deinen Webauftritt bei einer falschen Konfiguration offline nehmen – nämlich eine Caching-Richtlinie für alle möglichen Webbrowser etablieren.

Hier ist unsere optimierte .htaccess Datei für deine WooCommerce Installation. Dabei wird sichergestellt, dass dynamische Seiten wie der Warenkorb, Checkout und Mein Konto nicht zwischengespeichert werden, während statische Ressourcen wie Bilder, CSS und JavaScript gecacht werden, um die Ladezeiten zu verbessern.

# BEGIN WordPress
# Die Anweisungen (Zeilen) zwischen „BEGIN WordPress“ und „END WordPress“ sind
# dynamisch generiert und sollten nur über WordPress-Filter geändert werden.
# Alle Änderungen an den Anweisungen zwischen diesen Markierungen werden überschrieben.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

# Caching-Richtlinie für WooCommerce (statische Inhalte zwischenspeichern, dynamische Seiten nicht)
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 month"

  # Statische Inhalte
  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/webp "access plus 1 year"
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType text/javascript "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
  ExpiresByType application/x-javascript "access plus 1 month"
  ExpiresByType application/font-woff "access plus 1 year"
  ExpiresByType application/font-woff2 "access plus 1 year"
  ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
  ExpiresByType application/x-font-ttf "access plus 1 year"
  ExpiresByType font/ttf "access plus 1 year"
  ExpiresByType font/otf "access plus 1 year"
  ExpiresByType font/woff "access plus 1 year"
  ExpiresByType font/woff2 "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"
  ExpiresByType application/pdf "access plus 1 month"
  ExpiresByType text/html "access plus 1 hour"

  # Kein Caching für WooCommerce-Dynamik
  <FilesMatch "^(cart|checkout|my-account|wc-api|addons|logout|lost-password|wp-login|wp-admin|wc-ajax=).*">
    ExpiresActive Off
    Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0"
    Header set Pragma "no-cache"
  </FilesMatch>
</IfModule>

# Gzip-Komprimierung für bessere Performance
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css
  AddOutputFilterByType DEFLATE application/xml application/xhtml+xml application/rss+xml application/javascript application/x-javascript
  AddOutputFilterByType DEFLATE image/svg+xml application/font-woff application/font-woff2 application/x-font-ttf font/ttf font/otf
</IfModule>

# Browser-Caching optimieren
<IfModule mod_headers.c>
  <FilesMatch "\.(ico|jpe?g|png|gif|svg|webp|css|js|woff|woff2|ttf|otf|eot|pdf|mp4|avi|mov)$">
    Header set Cache-Control "public, max-age=31536000, immutable"
  </FilesMatch>
  <FilesMatch "\.(html|htm|xml|json)$">
    Header set Cache-Control "no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires 0
  </FilesMatch>
</IfModule>
Inhaltsverzeichnis