GoWebTools

Htaccess Generator

Generate .htaccess rules for Apache: HTTPS and www redirects, 301 redirects, caching headers, compression, security headers and custom error pages.

.htaccess

The result appears here as you type.

What this tool is for

Apache configuration written from memory tends to end in a 500 error or a redirect loop. Tick the rules you want, get a commented file back. The security header block is worth taking even if you came for something else: it is the cheapest hardening available on a shared host.

How to use it

  1. Select the rules you need: force HTTPS, canonical www, compression, caching, security headers.
  2. Add any custom 301 redirects.
  3. Back up your existing .htaccess before replacing it.
  4. Upload and test immediately: a syntax error here takes the whole site down with a 500.

Frequently asked questions

My site broke with a 500 error after uploading.

Apache refuses the whole file on one bad directive, usually a module that is not loaded, such as mod_rewrite or mod_deflate. Restore the backup, then add rules back in small groups to find the offender.

Does .htaccess work on Nginx?

No. Nginx has no per-directory configuration file at all: the equivalent rules go in the server block and require a reload.

Which security headers should I set?

Start with X-Content-Type-Options, Referrer-Policy and a Permissions-Policy. Content-Security-Policy is the strongest of them and the one most likely to break your own scripts, so add it last and test carefully.