.htaccess explained: the tiny file that controls redirects and security
What .htaccess does: https redirects, blocking bad bots, custom error pages and cache rules — the copy-paste snippets every site owner needs.
A tiny file named .htaccess sits in your website folder and gives Apache-compatible servers instructions: redirects, protection, caching. Here is what it can do for your site.
The safe copy-paste snippets
1. Force https (after SSL is active):
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
2. Custom 404 page:
ErrorDocument 404 /404.html
3. Block a troublemaker (repeated bot hits in your logs):
order allow,deny
deny from 203.0.113.5
allow from all
4. Protect the config file of a custom PHP app:
<Files "config.php"> require all denied </Files>
The rules that keep you safe
- ONE typo can take the whole site down (500 error) — always copy working snippets, never freehand
- Keep a backup of the file before editing (or use Kairalmas file versioning — one click restores)
- Test in a private window after every change
What Kairalmas pre-configures
Every vhost ships with protection for .env/.git/.htaccess files and https-ready structure — most sites never need manual .htaccess work beyond the force-https snippet.
When you actually need it
Migrations (redirect old URLs to new), forcing https, custom error pages, blocking scrapers. Everything else is optional polish — and the file manager's editor makes each change a two-minute, reversible task.