.htaccess Generator
Generate a .htaccess file for Apache web servers with redirects, security rules, and more online for free.
URL & Redirects
Trailing Slash
Custom Redirects
Performance
Default cache duration
Security
Block IPs (one per line)
Error Pages
Generated .htaccess
# Generated by Sawbank .htaccess Generator
# ── Rewrites ──────────────────────────────
RewriteEngine On
# Force HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# ── GZIP Compression ──────────────────────
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css
AddOutputFilterByType DEFLATE application/xml application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml application/javascript
AddOutputFilterByType DEFLATE application/x-javascript application/json
AddOutputFilterByType DEFLATE image/svg+xml
</IfModule>
# ── Browser Caching ──────────────────────
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType application/font-woff2 "access plus 1 year"
</IfModule>
# ── Security Headers ─────────────────────
<IfModule mod_headers.c>
Header always set X-Content-Type-Options "nosniff"
Header always set X-Frame-Options "SAMEORIGIN"
Header always set X-XSS-Protection "1; mode=block"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
Header always set Permissions-Policy "camera=(), microphone=(), geolocation=()"
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
</IfModule>
# ── Disable Directory Listing ────────────
Options -IndexesPlace .htaccess in your Apache web root directory.
Informazioni su questo strumento
Generate a .htaccess configuration file for Apache servers. Add custom redirects, enable HTTPS, configure CORS, set security headers, enable GZIP compression, and more.
Come usare
Choose Features
Toggle the options you need: redirects, HTTPS, CORS, headers, GZIP.
Configure
Fill in specific values like redirect paths or allowed origins.
Download
Preview and download the .htaccess file.
Casi d'uso
Server Configuration
Quickly configure Apache server rules without memorizing htaccess syntax.
Domande frequenti
Will this work on all Apache servers?
Rules require mod_rewrite and mod_headers to be enabled. Most shared hosting enables these by default.