← Të gjitha mjetet e sigurisë pwn.watch
Gjenerues .htaccess: Ridrejtime, HTTPS dhe header-a sigurie
Krijo një skedar Apache .htaccess: detyro HTTPS, zgjidh www ose pa www, shto ridrejtime 301, cakto header-at HSTS / CSP / X-Frame-Options, blloko hotlinking-un dhe IP-të, si dhe aktivizo cache dhe gzip.
Quick security presets
HTTPS dhe hosti kanonik
Ridrejtime 301
→
Shtegu i vjetër duhet të fillojë me /. Objektivi: një shteg ose URL e plotë https://.
Kokat e sigurisë
Të duhet CSP më e rreptë? Krijoje me gjeneratorin CSP.
Kontrolli i qasjes dhe forcimi i sigurisë
Performanca
.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>
I sponsorizuar
Me mbështetjen eTinkerer Club
Klubi privat për ata që zotërojnë serverët e tyre, përdorin AI-n e tyre dhe paguajnë 0 $/muaj për softuer.
Pyetje të shpeshta për .htaccess
- Si ta detyroj HTTPS me .htaccess?
- Aktivizo mod_rewrite dhe shto: RewriteEngine On, RewriteCond %{HTTPS} off, RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]. Nëse je pas një proxy ose load balancer-i, testo %{HTTP:X-Forwarded-Proto} në vend të %{HTTPS}.
- Si të shkruaj një ridrejtim 301 në .htaccess?
- Për një shteg, përdor mod_alias: Redirect 301 /old-page /new-page. Për të zhvendosur një domen të tërë, përdor mod_rewrite me RewriteCond %{HTTP_HOST} për hostin e vjetër dhe RewriteRule ^(.*)$ https://new.example/$1 [L,R=301].
- Cilët header-a sigurie duhet të vendos në .htaccess?
- Strict-Transport-Security (HSTS), Content-Security-Policy, X-Frame-Options ose CSP frame-ancestors, X-Content-Type-Options: nosniff, Referrer-Policy dhe Permissions-Policy. Kërkojnë mod_headers. Aktivizo HSTS vetëm pasi çdo nën-domen të ofrojë HTTPS.
- Si ta çaktivizoj listimin e direktorive?
- Shto Options -Indexes. Apache kthen 403 për dosjet pa skedar indeksi, në vend që të listojë përmbajtjen e tyre.
- Pse skedari im .htaccess nuk bën asgjë?
- Vhost-i duhet të lejojë mbishkrimet (AllowOverride All, ose të paktën FileInfo, Options, AuthConfig, Limit), dhe modulet e përdorura (mod_rewrite, mod_headers, mod_expires, mod_deflate) duhet të jenë të ngarkuara. Nginx e shpërfill plotësisht .htaccess.
- A dërgohet diçka te një server?
- Jo. Skedari krijohet në shfletuesin tënd; asgjë që shkruan nuk ngarkohet.