Why does my site show a 500 error after adding .htaccess?
A module is probably missing, or the host forbids a directive. Every block is wrapped in IfModule where possible; check the Apache error log for the exact line.
One redirect, not a chain.
Tick the rules you need and get a commented .htaccess for Apache 2.4. HTTPS and the www choice collapse into a single 301, your domain is escaped correctly, and sensitive files such as .env.local and logs are blocked.
Loading the toolbox.
You do not have to take our word that your data stays here. Developer tools show every request a page makes, so you can watch this page work and confirm that nothing is sent. The check takes under a minute.
F12, or Cmd+Option+I on a Mac, and select the Network tab.Only two things can add a line to that log, and neither carries your data. Submitting the feedback form sends the vote and comment you typed. Typing characters in a script the page has not displayed yet, such as Cyrillic or Greek, can make the browser fetch the matching font file, and that request names only the font.
The production site also sends a Content-Security-Policy header that tells your browser to refuse connections to anywhere except this site and the anonymous analytics endpoint, so a coding mistake could not quietly send your data elsewhere.
An .htaccess file holds Apache configuration for one folder and everything under it. Shared hosts use it because customers cannot edit the main server config. It is read on every request, so on a server you control, the same rules belong in the virtual host instead, where they are faster. The rules this tool writes work in either place.
With separate rules for HTTPS and for www, a visitor to http://example.com is sent to https://example.com and then again to https://www.example.com. Every extra hop costs a round trip, and search engines follow only a limited number of them. The original 2htaccess produced exactly that chain.
This version writes both conditions joined with [OR] in front of one rule whose target is the final origin, so any wrong scheme or wrong host reaches the canonical URL in a single 301. Behind a load balancer or CDN that ends TLS, %{HTTPS} is always off; the output says to test X-Forwarded-Proto there instead.
The vanilla deny rule only matched files named exactly .env or .log, so .env.local, .env.production, and error.log were served to anyone who asked. The new rule blocks:
Because FilesMatch only sees file names, the output also returns 404 for any path inside a .git, .svn, or .hg folder. .well-known stays reachable, since certificate renewal depends on it.
Elsewhere in the toolbox: 2hash, 2base, 2otp, 2xml, and more on the 2toolbox home page. Part of the 2suite.io privacy-first ecosystem.
A module is probably missing, or the host forbids a directive. Every block is wrapped in IfModule where possible; check the Apache error log for the exact line.
No. Nginx does not read .htaccess files. The same ideas apply, but the syntax is different.
Browsers cache 301 redirects for a long time. Test with a 302 first if you are unsure, then switch.
Apache 2.4. The file-blocking rule uses Require all denied, which replaced the 2.2 Order and Deny syntax.