← Alle Sicherheitstools von pwn.watch
.htaccess-Generator: Weiterleitungen, HTTPS & Sicherheitsheader
Erstelle eine Apache-.htaccess-Datei: Erzwinge HTTPS, wähle www oder ohne www, füge 301-Weiterleitungen hinzu, setze HSTS-, CSP- und X-Frame-Options-Header, blockiere Hotlinking und IPs und aktiviere Caching und gzip.
Quick security presets
HTTPS & kanonischer Host
301-Weiterleitungen
→
Der alte Pfad muss mit / beginnen. Ziel: ein Pfad oder eine vollständige https:// URL.
Sicherheits-Header
Du brauchst eine strengere CSP? Erstell sie mit dem CSP-Generator.
Zugriffsschutz & Härtung
Performance
.htaccess
# Generated by pwn.watch/tools/htaccess-generator
# ----- Hardening -----
Options -Indexes
<FilesMatch "^\.(?!well-known)">
Require all denied
</FilesMatch>
<FilesMatch "\.(bak|config|sql|ini|log|sh|swp|dist)$">
Require all denied
</FilesMatch>
# ----- HTTPS, www & rewrite rules (mod_rewrite) -----
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
</IfModule>
# ----- 301 redirects (mod_alias) -----
Redirect 301 /old-page /new-page
# ----- Security headers (mod_headers) -----
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains" "expr=%{HTTPS} == 'on'"
Header always set Content-Security-Policy "default-src 'self'; frame-ancestors 'self'; object-src 'none'; base-uri 'self'"
Header always set X-Frame-Options "SAMEORIGIN"
Header always set X-Content-Type-Options "nosniff"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
Header always set Permissions-Policy "camera=(), microphone=(), geolocation=()"
Header unset X-Powered-By
</IfModule>
# ----- Brotli compression (mod_brotli) -----
<IfModule mod_brotli.c>
AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/css text/xml text/javascript
AddOutputFilterByType BROTLI_COMPRESS application/javascript application/json application/xml application/rss+xml image/svg+xml
</IfModule>
# ----- Gzip compression (mod_deflate) -----
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml text/javascript
AddOutputFilterByType DEFLATE application/javascript application/json application/xml application/rss+xml image/svg+xml
</IfModule>
# ----- Browser caching (mod_expires) -----
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 hour"
ExpiresByType text/html "access plus 0 seconds"
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType image/avif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType font/woff2 "access plus 1 year"
</IfModule>
Gesponsert
Präsentiert vonTinkerer Club
Der private Club für alle, die ihre eigenen Server und ihre eigene KI betreiben und 0 $ pro Monat für Software zahlen.
.htaccess FAQ
- Wie erzwinge ich HTTPS mit .htaccess?
- Aktiviere mod_rewrite und füge Folgendes hinzu: RewriteEngine On, RewriteCond %{HTTPS} off, RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]. Hinter einem Proxy oder Load-Balancer prüfe %{HTTP:X-Forwarded-Proto} statt %{HTTPS}.
- Wie richte ich eine 301-Weiterleitung in .htaccess ein?
- Für einen einzelnen Pfad nutze mod_alias: Redirect 301 /old-page /new-page. Für eine ganze Domain nutze mod_rewrite mit RewriteCond %{HTTP_HOST} für den alten Host und RewriteRule ^(.*)$ https://new.example/$1 [L,R=301].
- Welche Sicherheits-Header sollte ich in .htaccess setzen?
- Strict-Transport-Security (HSTS), Content-Security-Policy, X-Frame-Options oder CSP frame-ancestors, X-Content-Type-Options: nosniff, Referrer-Policy und Permissions-Policy. Dafür brauchst du mod_headers. Aktiviere HSTS erst, wenn alle Subdomains HTTPS unterstützen.
- Wie deaktiviere ich die Verzeichnisauflistung?
- Füge Options -Indexes hinzu. Apache liefert dann für Ordner ohne Indexdatei 403 zurück, statt deren Inhalt aufzulisten.
- Warum bewirkt meine .htaccess-Datei nichts?
- Der vhost muss Overrides erlauben (AllowOverride All oder mindestens FileInfo, Options, AuthConfig, Limit). Außerdem müssen die verwendeten Module (mod_rewrite, mod_headers, mod_expires, mod_deflate) geladen sein. Nginx ignoriert .htaccess vollständig.
- Wird etwas an einen Server gesendet?
- Nein. Die Datei wird in deinem Browser erstellt. Nichts, was du eingibst, wird hochgeladen.