An .htaccess file gives the web server instructions for the folder it’s in, and every folder below. It’s how you set redirects, block access and change caching without server-wide access.
Where it lives
Usually public_html/.htaccess. A subfolder can have its own, adding to or overriding the parent’s rules. It’s a hidden file. How to show hidden files like .htaccess
What people use it for
| Job | Guide |
|---|---|
| Force HTTPS | How to force HTTPS (redirect HTTP to HTTPS) |
| Redirect pages or domains | Redirects with .htaccess: copy-ready examples |
| Custom 404 pages | Creating custom 404 and error pages |
| Security headers | Adding security headers with .htaccess |
| Block access to files | Storing configuration and secrets outside public_html |
| Password protection | How to password-protect a folder |
| Clean URLs for apps | Written by WordPress and frameworks |
WordPress’s block
WordPress manages a section between # BEGIN WordPress and # END WordPress. Put your own rules above it; WordPress rewrites the inside of its block when you save permalinks.
The golden rule: one mistake breaks everything
A typo in .htaccess returns a 500 Internal Server Error for the whole folder immediately.
- Copy the file before editing (
.htaccess.bak). - Make one change at a time.
- Reload the site straight after saving.
- If you get a 500, restore the copy.
Diagnosing a broken .htaccess
Rename it to .htaccess-off. If the site returns, the file was the cause. The domain’s error log names the problem line, such as “Invalid command” or “RewriteRule: bad flag”. Viewing website statistics and logs in DirectAdmin
Performance
The server reads .htaccess files on every request. Keep them tidy: remove rules from plugins you no longer use.
Traxio accounts include SSH, Git, cron and PHP 7.4 to 8.3. Try the PHP hosting is free for 30 days with no card, then £0.99 a month.