← Vsa varnostna orodja pwn.watch
Generator .htaccess: preusmeritve, HTTPS in varnostne glave
Ustvari datoteko Apache .htaccess: vsili HTTPS, izberi www ali brez www, dodaj preusmeritve 301, nastavi glave HSTS / CSP / X-Frame-Options, blokiraj neposredno povezovanje do datotek in IP-je ter vklopi predpomnjenje in gzip.
Quick security presets
HTTPS in kanonična gostiteljska domena
Preusmeritve 301
→
Stara pot se mora začeti z /. Cilj: pot ali celoten URL https://.
Varnostne glave
Potrebuješ strožji CSP? Sestavi ga z generatorjem CSP.
Nadzor dostopa in utrjevanje varnosti
Zmogljivost
.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>
Sponzorirano
SponzoriraTinkerer Club
Zasebni klub za tiste, ki imajo svoje strežnike, poganjajo svoj AI in za programsko opremo plačujejo 0 $ na mesec.
Pogosta vprašanja o .htaccess
- Kako z .htaccess vsilim HTTPS?
- Omogoči mod_rewrite in dodaj: RewriteEngine On, RewriteCond %{HTTPS} off, RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]. Za proxyjem ali izravnalnikom obremenitve preveri %{HTTP:X-Forwarded-Proto} namesto %{HTTPS}.
- Kako v .htaccess nastavim preusmeritev 301?
- Za eno pot uporabi mod_alias: Redirect 301 /old-page /new-page. Za selitev celotne domene uporabi mod_rewrite z RewriteCond %{HTTP_HOST} za staro gostiteljsko ime in RewriteRule ^(.*)$ https://new.example/$1 [L,R=301].
- Katere varnostne glave naj nastavim v .htaccess?
- Strict-Transport-Security (HSTS), Content-Security-Policy, X-Frame-Options ali CSP frame-ancestors, X-Content-Type-Options: nosniff, Referrer-Policy in Permissions-Policy. Potrebujejo mod_headers. HSTS omogoči šele, ko vse poddomene uporabljajo HTTPS.
- Kako izklopim prikaz vsebine map?
- Dodaj Options -Indexes. Apache nato za mape brez indeksne datoteke vrne 403, namesto da prikaže njihovo vsebino.
- Zakaj moja datoteka .htaccess ne naredi ničesar?
- Vhost mora dovoljevati preglasitve (AllowOverride All ali vsaj FileInfo, Options, AuthConfig, Limit), uporabljeni moduli (mod_rewrite, mod_headers, mod_expires, mod_deflate) pa morajo biti naloženi. Nginx datoteke .htaccess sploh ne upošteva.
- Se kaj pošlje na strežnik?
- Ne. Datoteka se sestavi v brskalniku; ničesar, kar vneseš, ne naložimo.