← Alle beveiligingstools van pwn.watch
.htaccess-generator: omleidingen, HTTPS en beveiligingsheaders
Maak een Apache .htaccess-bestand: forceer HTTPS, kies www of non-www, voeg 301-omleidingen toe, stel HSTS / CSP / X-Frame-Options-headers in, blokkeer hotlinking en IP's, en schakel caching en gzip in.
Quick security presets
HTTPS en canonieke host
301-omleidingen
→
Oud pad moet beginnen met /. Doel: een pad of volledige https://-URL.
Beveiligingsheaders
Wil je een strengere CSP? Stel er een samen met de CSP-generator.
Toegangsbeheer en beveiliging
Prestaties
.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>
Gesponsord
Aangeboden doorTinkerer Club
De besloten club voor mensen met eigen servers en AI, die $0 per maand betalen voor software.
.htaccess FAQ
- Hoe dwing ik HTTPS af met .htaccess?
- Schakel mod_rewrite in en voeg toe: RewriteEngine On, RewriteCond %{HTTPS} off, RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]. Test achter een proxy of load balancer %{HTTP:X-Forwarded-Proto} in plaats van %{HTTPS}.
- Hoe stel ik een 301-redirect in met .htaccess?
- Gebruik voor één pad mod_alias: Redirect 301 /old-page /new-page. Gebruik voor een volledige domeinverhuizing mod_rewrite met RewriteCond %{HTTP_HOST} voor de oude host en RewriteRule ^(.*)$ https://new.example/$1 [L,R=301].
- Welke beveiligingsheaders stel ik in met .htaccess?
- Strict-Transport-Security (HSTS), Content-Security-Policy, X-Frame-Options of CSP frame-ancestors, X-Content-Type-Options: nosniff, Referrer-Policy en Permissions-Policy. Hiervoor heb je mod_headers nodig. Schakel HSTS pas in als alle subdomeinen HTTPS gebruiken.
- Hoe schakel ik mapvermeldingen uit?
- Voeg Options -Indexes toe. Apache geeft dan 403 terug voor mappen zonder indexbestand, in plaats van de inhoud te tonen.
- Waarom doet mijn .htaccess-bestand niets?
- De vhost moet overrides toestaan (AllowOverride All, of minstens FileInfo, Options, AuthConfig, Limit), en de gebruikte modules (mod_rewrite, mod_headers, mod_expires, mod_deflate) moeten geladen zijn. Nginx negeert .htaccess volledig.
- Wordt er iets naar een server gestuurd?
- Nee. Het bestand wordt in je browser samengesteld; niets wat je invult, wordt geüpload.