Skip to content
ZeroServer.tools

Apache .htaccess Generator

Generate common Apache .htaccess rules — HTTPS redirects, caching, Gzip, custom error pages, and more.

Options

WWW handling

604800 = 1 week, 2592000 = 30 days, 31536000 = 1 year

HTTPS Redirect: YesGzip: EnabledLines: 40Bytes: 1212

About Apache .htaccess Generator

The .htaccessfile is Apache's per-directory configuration file. It lets you set redirects, authentication, custom error pages, URL rewriting, compression, and cache headers without modifying the main server config. This generator produces rules using mod_rewrite, mod_deflate, and mod_expires — all standard Apache modules.

Built and maintained by Meet Shah · Last updated

What this tool is used for

  • Producing an HTTPS redirect rule without hand-writing the rewrite conditions.
  • Adding canonical www or non-www redirection consistently.
  • Setting cache headers for static assets on a shared host.
  • Enabling compression where you cannot change the server config.
  • Turning off directory listing on a host you do not fully control.

Frequently Asked Questions

Where does the file go and why the leading dot?
In the directory it should govern — rules apply to that directory and everything beneath it. The leading dot makes it hidden on Unix, which is why `ls` appears to show an empty directory and why the file is so often "missing" after an upload.
Why is it slower than the main config?
Because Apache re-reads it on *every request*, and checks every parent directory for one too. The main `httpd.conf` is read once at startup. If you control the server, put the rules there and set `AllowOverride None` — the difference is measurable under load.
My rules do nothing at all — why?
Almost always `AllowOverride`. If it is set to None for that directory, the file is ignored entirely and silently. After that, check `mod_rewrite` is enabled, then that the file has not been uploaded in binary mode with CRLF line endings.
Which redirect should I use?
301 for a permanent move — it passes ranking signals and browsers cache it hard, which is precisely why testing one is painful. Use 302 while you are still deciding, and test in a private window so a cached 301 does not follow you around.
Does it work on nginx?
No. `.htaccess` is an Apache feature with no nginx equivalent by design — nginx deliberately rejected per-directory config files for the performance reason above. The rules must be translated into `server` and `location` blocks and reloaded.

Common errors and gotchas

  • Writing a redirect that loops, which is easy when both HTTPS and www rules interact.
  • Assuming the file is read, when `AllowOverride` may be off and the rules silently ignored.
  • Ordering rules wrongly, since the first matching rewrite can stop the rest from applying.
  • Setting very long cache lifetimes on files that change, with no cache-busting in their names.
  • Testing on a host with a different Apache version, where directive support differs.

Related Generators tools

Private & free — this tool runs entirely in your browser.

BluehostReliable WordPress & web hosting — exclusive pricing from $3.79/mo.affiliate