Beispiel 1: Neue Website auf example.com
Eingabe:
- Domain: example.com
- HTTPS erzwingen, Adresse immer ohne www
- GZIP-Komprimierung an
- Caching: Bilder 1 Monat, CSS und JavaScript 1 Woche, HTML immer neu prüfen
- Verzeichnislisten ausschalten
Ausgabe (.htaccess):
# .htaccess erzeugt mit dem .htaccess Generator von ZAP-Hosting
# Vor dem Hochladen: Sicherungskopie anlegen und zuerst auf einer Testumgebung prüfen.
# HTTPS und Domain-Schreibweise
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Allgemeines und Sicherheit
Options -Indexes
# Komprimierung
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml text/javascript application/javascript application/json application/ld+json application/xml application/xhtml+xml application/rss+xml application/atom+xml image/svg+xml image/x-icon font/ttf font/otf application/vnd.ms-fontobject
</IfModule>
# Browser-Caching
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/webp "access plus 1 month"
ExpiresByType image/avif "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 month"
ExpiresByType text/css "access plus 1 week"
ExpiresByType text/javascript "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType text/html "access plus 0 seconds"
ExpiresByType application/xhtml+xml "access plus 0 seconds"
</IfModule>
Ergebnis in Worten: Eine Adresse wie http://www.example.com/seite geht mit einer einzigen 301-Weiterleitung auf https://example.com/seite. Aufrufe über http:// ohne www landen ebenfalls per 301 bei https://. Bilder bleiben 1 Monat im Browser-Cache (max-age=2592000), CSS und JavaScript 1 Woche und HTML-Seiten werden bei jedem Besuch neu geprüft. HTML, CSS, JavaScript und JSON werden mit GZIP komprimiert übertragen. Wer einen Ordner ohne index-Datei aufruft, sieht keine Dateiliste mehr, sondern einen Fehler 403.
