What is .htaccess? A practical guide
What .htaccess files do, where they apply, the rules people use most, and how to recover quickly when one breaks your site.
On this page
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.
Prefer to follow along?
- Diagnose a 500 Internal Server Error
Intermediate · 20 min - Redirect old URLs after a redesign
Intermediate · 30 min
Traxio accounts include SSH, Git, cron and PHP 7.4 to 8.4. Try the PHP hosting is £0.99 a month.
If it doesn’t work
These guides cover the most common problems, starting with what you can see. Or browse every fix for a common problem.
- 500 Internal Server Error: how to fix itFind the real cause of a 500 error: read the error log, then check .htaccess, PHP errors, permissions and PHP version in order.
- Cron job not runningDiagnose a cron job that doesn’t seem to run: wrong schedule, relative paths, PHP binary, permissions, silent errors and overlapping runs.
- “Too many redirects” and HTTPS redirect loopsFix ERR_TOO_MANY_REDIRECTS: conflicting HTTPS and www rules in .htaccess, WordPress settings, plugins and Cloudflare’s SSL mode.
- 403 Forbidden: how to fix itWhy the server refuses access with a 403 — missing index file, permissions, .htaccess rules or security blocks — and how to fix each one.
Common questions
What is Apache, and why does .htaccess matter?
Apache is long-established web server software, and .htaccess is its per-folder configuration file. The format matters beyond Apache itself because other web servers, including LiteSpeed, read the same file — which is why .htaccess instructions work across most shared hosting.
This is a general web-hosting explanation, not specific to Traxio.
What is an .htaccess file?
.htaccess is a configuration file that changes how the web server handles requests for the folder it sits in — redirects, custom error pages, access rules and caching headers. It takes effect immediately, with no restart needed.
This is a general web-hosting explanation, not specific to Traxio.
Because it applies instantly, a syntax error in .htaccess takes the whole site down with a 500 error. Always keep a copy of the working version before editing, and it is a hidden file, so turn on “show hidden files” in the File Manager to see it.
Spotted something out of date or unclear? Tell us and we’ll fix it.