📄 .htaccess Generator
Generate Apache .htaccess config: redirects, HTTPS enforcement, www handling, gzip, caching
Use 301 (permanent) by default. Add 302 after the path for temporary: /temp /new 302.
Place this file in your web root. Apache reads .htaccess on every request when AllowOverride All is set in the VirtualHost.
About this tool
The .htaccess file is Apache's per-directory configuration mechanism — it controls redirects, rewrites, headers, caching, and access restrictions without touching the main server config. Writing one from memory is error-prone: a mis-ordered RewriteRule creates infinite redirect loops, a missing mod_headers wrapper produces 500 errors, and copy-pasted gzip directives often break on newer Apache versions. This generator produces a clean, correctly ordered .htaccess from a checkbox-driven form.
Select your domain, toggle the features you need, and the output updates in real time. For example: choosing Force HTTPS + www → non-www generates a mod_rewrite block that redirects both http://www.example.com and http://example.com to https://example.com in a single pass. The Production preset enables HTTPS enforcement, HSTS, gzip, caching, security headers, sensitive-file blocking, and directory-index suppression.
Custom redirects accept a simple old-path → new-url format (one per line) and default to 301 (permanent). Append 302 for temporary redirects. All <IfModule> wrappers mean the config degrades gracefully if a module is not loaded.
FAQ
Where do I put the .htaccess file? ›
Place it in your web root directory — usually public_html, htdocs, or /var/www/html. Apache reads .htaccess from that directory and (by default) all its subdirectories. Make sure AllowOverride All (or at least FileInfo Options) is set in your VirtualHost or main Apache config, otherwise .htaccess directives are ignored.
Why wrap directives in <IfModule>? ›
If a module (like mod_rewrite, mod_headers, or mod_deflate) is not loaded, directives inside the <IfModule> block are silently skipped instead of causing a 500 Internal Server Error. This makes the config safe to deploy on unknown hosting environments. The generator uses these wrappers everywhere.
How do I test that my .htaccess works? ›
Save the file, then use curl -I https://example.com to inspect response headers. For redirects, curl -I http://example.com should return 301 with a Location: https://example.com. Browser DevTools → Network tab also shows every redirect and response header. If you get a 500 error, check Apache's error log — usually /var/log/apache2/error.log or /var/log/httpd/error_log.
What's the difference between 301 and 302 redirects? ›
301 means the page has moved permanently — browsers cache the redirect and search engines transfer ranking to the new URL. 302 means temporary — browsers re-check every time and search engines keep indexing the old URL. Use 301 for structural changes (domain moves, URL cleanup) and 302 for maintenance windows or A/B tests.