Skip to main content

.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 -Indexes

Place .htaccess in your Apache web root directory.

About This Tool

Generate a .htaccess configuration file for Apache servers. Add custom redirects, enable HTTPS, configure CORS, set security headers, enable GZIP compression, and more.

How to Use

  1. Choose Features

    Toggle the options you need: redirects, HTTPS, CORS, headers, GZIP.

  2. Configure

    Fill in specific values like redirect paths or allowed origins.

  3. Download

    Preview and download the .htaccess file.

Use Cases

Server Configuration

Quickly configure Apache server rules without memorizing htaccess syntax.

Frequently Asked Questions

Will this work on all Apache servers?

Rules require mod_rewrite and mod_headers to be enabled. Most shared hosting enables these by default.

Sawbank

Công cụ PDF Chuyên nghiệp - Miễn phí & Riêng tư

Security

  • Client-side processingFiles never leave your device
  • No file uploads100% private & secure

Compliance

GDPR Compliant
100% Riêng tư - Tệp không bao giờ rời khỏi thiết bị
Chọn Ngôn ngữ

© 2026 Sawbank. Bảo lưu mọi quyền.