.htaccess Generator
Toggle the rules you need — force HTTPS, www or non-www redirects, disable directory listing, block dotfiles, enable gzip and browser caching, custom error pages, and CORS — and get a ready-to-use Apache .htaccess. Copy or download instantly.
Force HTTPS
Redirect all HTTP traffic to HTTPS
Disable directory listing
Hide folder contents (Options -Indexes)
Block dotfiles
Deny access to .env, .git, etc.
Gzip compression
Compress text responses
Browser caching
Cache static assets
Custom error pages
404.html / 500.html
CORS: allow all origins
Access-Control-Allow-Origin: *
<IfModule mod_rewrite.c>
RewriteEngine On
# Force HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
# Disable directory listing
Options -Indexes
# Block access to dotfiles (.env, .git, etc.)
<FilesMatch "^\.">
Require all denied
</FilesMatch>
# Gzip compression
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript application/javascript application/json image/svg+xml
</IfModule>
# Browser caching
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "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"
</IfModule>
Tip: place this file in your site's root. Test on staging first — a bad rule can take a site offline.
How to create an .htaccess file
Generate Apache .htaccess rules for redirects, performance, and security.
- 1
Pick options
Toggle the rules you need, like Force HTTPS or gzip compression.
- 2
Review
The .htaccess updates live as you change options.
- 3
Deploy
Download the file to your site root — test on staging first.