htaccess Rule Generator
Generate an Apache .htaccess file: force HTTPS, www/non-www redirects, 301s, gzip, caching and security. Free, deterministic, in your browser.
Generate .htaccess rules
Pick the rules you need. We build the .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
# Force HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
# Gzip compression
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/css application/javascript application/json image/svg+xml
</IfModule>
# Browser caching
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
</IfModule>
# Disable directory listing
Options -Indexes
What this .htaccess generator does
Common use cases
- 1Forcing HTTPS on Apache
- 2Migrating URLs with 301s
- 3Improving speed with caching/gzip
- 4Standardising the www version
- 5Hardening a shared host
- 6Adding a custom error page
Related tools
About .htaccess
.htaccess is Apache's per-directory config file. Placed in your site root, it can force HTTPS, redirect URLs, add caching and compression, and tighten security — without touching the main server config, which makes it ideal on shared hosting.
This generator builds a clean .htaccess from the options you select. Because a single syntax error can return a 500 and take the whole site down, always back up the existing file and test on staging first. Most rules here require Apache's mod_rewrite, mod_deflate and mod_expires modules.
More Free Tools Where This Came From
This utility is one of dozens of free, no-login tools for DNS, email, SEO and developers — all instant and private.
HostCloud.in · Pune, India · Serving 34,987+ Websites Since 2020
Got Questions? We Have Answers.
What rules can it generate?
Force HTTPS, www/non-www redirects, custom 301 redirects, gzip compression, browser caching, disabling directory listing, and a custom 404 page.
Where do I put the file?
In your site root as .htaccess. Back up any existing file and test on staging — a single error can return a 500 and take the site down.
What Apache modules are needed?
mod_rewrite for redirects, mod_deflate for gzip and mod_expires for caching.
Does it use AI or a server?
No. It builds the rules deterministically in your browser.
