Lumaktaw sa content

Magpa-notify

Magpa-email kapag may bagong malaking security incident. Walang spam, puwede kang mag-unsubscribe anumang oras.

Ginagamit lang para sa mga email tungkol sa incident sa pwn.watch. Protektado ng Cloudflare Turnstile.

← Lahat ng security tools ng pwn.watch

.htaccess Generator: Redirects, HTTPS at Security Headers

Gumawa ng Apache .htaccess file: i-force ang HTTPS, pumili ng www o walang www, magdagdag ng 301 redirects, mag-set ng HSTS / CSP / X-Frame-Options headers, i-block ang hotlinking at mga IP, at i-on ang caching at gzip.

Quick security presets

HTTPS at canonical host

301 redirects

→

Dapat magsimula sa / ang lumang path. Target: path o buong https:// URL.

Security headers

Kailangan ng mas mahigpit na CSP? Gumawa gamit ang CSP generator.

Access control at hardening

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>

Hatid ngTinkerer Club

Private club para sa mga may sariling servers, nagpapatakbo ng sariling AI, at $0/month ang gastos sa software.

.htaccess FAQ

Paano piliting gumamit ng HTTPS gamit ang .htaccess?
I-enable ang mod_rewrite at idagdag: RewriteEngine On, RewriteCond %{HTTPS} off, RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]. Kung nasa likod ng proxy o load balancer, subukan ang %{HTTP:X-Forwarded-Proto} sa halip na %{HTTPS}.
Paano gumawa ng 301 redirect sa .htaccess?
Para sa isang path, gamitin ang mod_alias: Redirect 301 /old-page /new-page. Para ilipat ang buong domain, gamitin ang mod_rewrite kasama ang RewriteCond %{HTTP_HOST} para sa lumang host at RewriteRule ^(.*)$ https://new.example/$1 [L,R=301].
Anong security headers ang dapat itakda sa .htaccess?
Strict-Transport-Security (HSTS), Content-Security-Policy, X-Frame-Options o CSP frame-ancestors, X-Content-Type-Options: nosniff, Referrer-Policy at Permissions-Policy. Kailangan ang mod_headers para gumana ang mga ito. I-enable lang ang HSTS kapag HTTPS na ang lahat ng subdomain.
Paano i-disable ang directory listing?
Idagdag ang Options -Indexes. Magbabalik ang Apache ng 403 para sa mga folder na walang index file, sa halip na ilista ang laman ng mga ito.
Bakit walang epekto ang .htaccess file ko?
Dapat payagan ng vhost ang overrides (AllowOverride All, o kahit FileInfo, Options, AuthConfig, Limit), at dapat naka-load ang mga module na ginagamit (mod_rewrite, mod_headers, mod_expires, mod_deflate). Ganap na hindi pinapansin ng Nginx ang .htaccess.
May ipinapadala ba sa server?
Wala. Sa browser mo binubuo ang file; walang ina-upload sa mga inilagay mo.