How to use
- Pick the options you need, top to bottom. The defaults are HTTPS redirect, hidden directory listings, blocked dotfiles, text compression and caching.
- To send an old URL to a new one, add the path under URL redirects and choose the type (301 permanent, 302 temporary, 307 and 308 keep the request method).
- Read the warnings, then copy the .htaccess result or download it as a file.
- Upload it to the site’s top folder (often
public_html) as.htaccess. If one exists, back it up first.
What each option writes
| Option | Apache module | Result |
|---|---|---|
| Force HTTPS | mod_rewrite | 301 redirect after RewriteCond %{HTTPS} !=on |
| www canonical | mod_rewrite | 301 to either the www or the non-www address |
| URL redirects | mod_alias | Redirect 301 /old /new |
| Compression | mod_deflate, mod_brotli | smaller HTML, CSS, JS, JSON and SVG transfers |
| Browser caching | mod_expires | long for images and fonts, 0 seconds for HTML |
| Security headers | mod_headers | nosniff, X-Frame-Options, Referrer-Policy, HSTS and more |
| Hotlink protection | mod_rewrite | 403 when another site loads your images directly |
| Hide listings, block dotfiles | core, access control | Options -Indexes, <FilesMatch "^\."> |
Every module rule is wrapped in <IfModule> so a missing module does not cause a 500 error. Directives that cannot be wrapped, such as Options -Indexes, fail if the server does not allow AllowOverride Options; the tool warns about it.
Example output
With only HTTPS redirect, www canonical, one redirect, a 404 page, hidden listings and blocked dotfiles selected (compression, caching and headers off) you get:
# .htaccess (Apache 2.4)
# Redirects
<IfModule mod_alias.c>
Redirect 301 /old-page /new-page
</IfModule>
# Rewrite rules
<IfModule mod_rewrite.c>
RewriteEngine On
# non-www to www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !^(localhost|[0-9.]+)(:[0-9]+)?$
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# force HTTPS
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
# Custom error pages
ErrorDocument 404 /404.html
# Disable directory listing
Options -Indexes
# Block hidden files such as .htaccess, .env, .git
<FilesMatch "^\.">
Require all denied
</FilesMatch>
When you pick both www canonical and HTTPS, the rules are ordered so http://example.com reaches https://www.example.com in a single hop. Two chained redirects cost both crawlers and visitors.
Before you use it
- Behind a proxy or CDN (Cloudflare and similar) the server may always see plain HTTP, and an HTTPS redirect then loops forever. Turn on the proxy option so the rule checks the
X-Forwarded-Protoheader instead. - HSTS makes browsers remember HTTPS-only for
max-age. UseincludeSubDomainsonly when every subdomain supports HTTPS. Preload list eligibility needs a max-age of at least one year andincludeSubDomains. - Authentication plus an IP rule passes when either one matches (OR). Requiring both needs a hand-written
<RequireAll>. - The www rule would also send a subdomain such as
blog.example.comtowww.blog.example.com. Do not use it if subdomains share the folder. - Nginx ignores
.htaccess; use the Nginx Config Generator there.
Frequently asked questions
I uploaded the file and got a 500 error.
Usually a required module is off, AllowOverride blocks the directive, or one line is wrong. The server error log names the offending line. Restore the backup you made before uploading.
What is the difference between 301 and 302?
301 is a permanent move, so search engines transfer ranking to the new address; 302 is temporary and keeps the original. See HTTP Status Codes for what each code means.
Where does the file go?
In the site’s web root (document root). A .htaccess in a subfolder applies only inside that folder. Its name starts with a dot, so enable hidden files in your FTP client to see it.
Does it control search engine crawling?
No. Crawl rules belong in robots.txt; use the robots.txt Generator.
For network ranges see the Firewall Rule Generator, and for the .htpasswd file behind password protection use the htpasswd Generator. What you enter is processed in your browser and never sent to a server.