.htaccess Generator
Build Apache .htaccess rules for HTTPS redirects, caching, GZIP, error pages, and security — with live preview and download.
Last updated: June 2026
Custom Error Pages
Live Preview
# URL Rewrites
RewriteEngine On
# Redirect HTTP to HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Disable directory browsing
Options -Indexes
# Protect sensitive files
<FilesMatch "(\.env|config\.php)$">
Order Allow,Deny
Deny from all
</FilesMatch>
.htaccess only works on Apache servers — Nginx uses server-block configuration instead.
About .htaccess Generator
Our free .htaccess Generator builds Apache configuration rules with toggles for HTTPS redirect, www handling, custom error pages, browser caching, GZIP, IP blocking, and file protection.
Live preview updates as you toggle rules. Copy to clipboard or download as .htaccess instantly. Inline help explains what each rule does.
No signup, runs entirely in your browser. Note: .htaccess only works on Apache — not Nginx.
Read the full guide: .htaccess file guide 2026 — redirects, caching & security
When Should You Use the .htaccess Generator?
HTTPS migration
Force all HTTP traffic to HTTPS with a permanent 301 redirect.
WWW canonicalization
Choose force www, remove www, or no change.
Performance tuning
Enable browser caching and GZIP compression for static assets.
Custom error pages
Route 404, 403, and 500 errors to branded pages.
Basic security
Block IPs, disable directory listing, protect .env files.
Frequently Asked Questions
Help Us Improve
Your feedback helps us build better tools.