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.

關於此工具

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

使用方法

  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.

使用場景

Server Configuration

Quickly configure Apache server rules without memorizing htaccess syntax.

常見問題

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

專業PDF工具 - 免費且私密

Security

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

Compliance

GDPR Compliant
100% 私密 - 檔案永不離開您的裝置
選擇語言

© 2026 Sawbank. 保留所有權利。