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.

Guide2 min readLast updated
On this page
  1. Where it lives
  2. What people use it for
  3. WordPress’s block
  4. The golden rule: one mistake breaks everything
  5. Diagnosing a broken .htaccess
  6. Performance
  7. If it doesn’t work
  8. Common questions

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

JobGuide
Force HTTPSHow to force HTTPS (redirect HTTP to HTTPS)
Redirect pages or domainsRedirects with .htaccess: copy-ready examples
Custom 404 pagesCreating custom 404 and error pages
Security headersAdding security headers with .htaccess
Block access to filesStoring configuration and secrets outside public_html
Password protectionHow to password-protect a folder
Clean URLs for appsWritten 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.

  1. Copy the file before editing (.htaccess.bak).
  2. Make one change at a time.
  3. Reload the site straight after saving.
  4. 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?

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.

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.

Keep going