.htaccess generator

HTTPS, one address, closed .env and .git, a folder password and rules for WordPress, Laravel and Bitrix — in one file.
The .htpasswd hash is computed in your browser.

.htaccess generator

Builds an .htaccess for Apache and LiteSpeed — what most ordinary hosting runs. It includes HTTPS and a single address with or without www in one redirect, closed .env, .git, backups and dumps, no directory listing, security headers and a password on a folder, a file or the whole site. Ready rules for WordPress, Laravel, 1C-Bitrix and single-page apps are included.

Only for the check commands: the rules themselves work for any domain.

HTTPS

Close access

Password

Result

.htaccess in the site root

   
The file downloads as htaccess.txt — rename it to .htaccess. If an .htaccess already exists, keep a copy of the old one.
Check after uploading

   

The files and the password hash are made in your browser; the password is sent nowhere.

What .htaccess closes

On ordinary hosting with Apache or LiteSpeed, site access is set up with an .htaccess file. By default the server serves everything in the site folder: the .env file with database passwords, the .git folder with source code, a forgotten backup.sql dump, the list of files in a folder without an index. Bots check these addresses on every site many times a day. The generator builds an .htaccess that closes them, moves the site to HTTPS and to one address with or without www in a single redirect (no http → https → no-www chain), adds security headers and, if needed, puts a password on the admin area.

How to use it

  1. Choose the site engine and the address you want — with or without www.
  2. If the hosting uses nginx in front or the site is behind Cloudflare, keep “nginx or a CDN sits in front of Apache” on — otherwise you get an endless redirect.
  3. Tick what to close. For a folder password set the folder, a login and the full path to .htpasswd on the server — keep the generated password or type your own.
  4. Keep a copy of the old .htaccess, upload the new one to the site root, and the folder files and .htpasswd to the paths shown.
  5. Run the check commands: .env and .git must answer 403, and http:// must lead to https://.

If something goes wrong

Error 500 right after uploading means the hosting does not allow some directive: most often Options or a wrong path to .htpasswd. Delete the line and look at the error log in the hosting panel. “Too many redirects” means nginx or a CDN handles HTTPS: turn on that box. For an nginx-only server there is the nginx config generator, headers can be checked in HTTP security headers, and an .htpasswd hash on its own is in password hashes.

Frequently asked questions

How do I redirect http to https in .htaccess?

With RewriteCond %{HTTPS} off and a RewriteRule to https://%{HTTP_HOST}%{REQUEST_URI} with code 301. If nginx or a CDN sits in front of Apache, Apache sees plain HTTP, so the X-Forwarded-Proto header must be checked too — the generator adds this with the “nginx or a CDN sits in front of Apache” box.

How do I password-protect a folder with .htaccess?

You need two files: an .htaccess in that folder with AuthType Basic, AuthUserFile and Require valid-user, and an .htpasswd file with a login:hash line. AuthUserFile takes the full path on the server, better outside the site folder. The generator makes both, and the bcrypt hash is computed in your browser. Without HTTPS the password travels almost in clear text.

Why is it important to close .env and .git?

.env holds database passwords and API and mail keys, and the whole site code with its history can be downloaded from the .git folder. Bots look for these files constantly, and a found .env usually means the database is breached the same day.

Will it work on my hosting?

Yes, if the site runs on Apache or LiteSpeed — that is most shared hosting. The rules are wrapped in IfModule, so a missing module will not break the site. If the hosting does not allow some directive, you get error 500 — then delete the line the error log points to.

More tools

Linux servers

Let’s Encrypt certificate
certbot commands with automatic renewal
SSH hardening
A secure sshd_config
SSH: config and keys
~/.ssh/config and authorized_keys with restrictions
Firewall rules
ufw, nftables, firewalld
fail2ban config
SSH, nginx and mail brute-force protection
systemd hardening
A sandbox for services: unit file or drop-in
Kernel settings (sysctl)
Linux network and kernel hardening, explained
sudoers rules
Who may run what via sudo, checked