Websites and Tech

htaccess

Also called .htaccess, hypertext access file

A per-folder text file that changes how an Apache server handles requests, commonly used for redirects and access rules.

Quick facts: htaccess

Category
Websites and Tech
Also called
.htaccess, hypertext access file
Level
Advanced
Affects
Redirects, HTTPS enforcement, canonical hostname, access control
Where to see it
Hosting file manager, FTP or SFTP client, your host's error log
In this article4
  1. How htaccess works
  2. Why htaccess matters
  3. Where htaccess goes wrong
  4. How to act on it

How htaccess works

An Apache web server reads its main configuration once at start-up. The .htaccess file is the exception: a small text file you place inside a folder, which Apache reads on every request for anything in that folder or below it. That is what makes it useful on shared hosting, where you have no access to the server’s own configuration but can still change how your site behaves.

What it controls is mostly traffic and access. It can send one address to another, force every request onto HTTPS, settle whether the site answers on the www version or the bare domain, protect a folder with a password, deny access to a file, set cache headers, or point missing pages at your own 404 page. On a WordPress site it also holds the rewrite rules that turn tidy URLs into something the software can answer.

Why htaccess matters

Most of the technical decisions that affect search sit in it. A redirect written here returns a real 301 before any code runs, which is cleaner and faster than a plugin doing the same job later. Choosing one canonical hostname and one protocol, and redirecting everything else to it, prevents the same page existing at several addresses and splitting its signals.

It is also the file that quietly decides whether a migration succeeds. When URLs change, the old ones have to keep working, and the mapping usually lives here. Getting it right is a large part of ordinary technical SEO work.

Where htaccess goes wrong

The first trap is that it may do nothing at all. It is an Apache feature, honoured by LiteSpeed too, but Nginx ignores it completely. Plenty of sites carry a carefully written file that has never been read, and plenty of guides hand out rules without saying which server they assume.

The second is fragility. A single mistyped line takes the whole site down with a server error rather than failing quietly, and because the file is read on every request, a long list of rules adds work to every page view. The third is accumulation: redirects added over years without review turn into chains, where one address points at another which points at a third, and sometimes into loops that make a page unreachable. Editing it through a plugin’s interface makes this worse, because nobody keeps a record of what was added or why.

How to act on it

Keep a copy before you touch it, and make the change when you can test immediately rather than at the end of the day. After every edit, load the home page, a deep page and a deliberately wrong address to confirm you get a page, a page and your 404 respectively.

Write redirects to the final destination rather than to another redirect, keep the WordPress block that the software manages separate from your own rules, and add a short comment above each rule saying what it is for. Review the file whenever you migrate or restructure, and delete rules whose reason has expired. If your host runs Nginx, do the same work in the server configuration instead and ignore any advice that assumes this file exists.

Do and do not

Do

  • Save a copy before every edit and test straight after
  • Point each redirect at its final destination, not another redirect
  • Comment each rule with the reason it exists

Do not

  • Assume it works — Nginx ignores it entirely
  • Edit the block WordPress manages for permalinks by hand
  • Let unreviewed rules pile up after migrations

Questions people ask about this

Where is the .htaccess file and why can I not see it?

It normally sits in the root folder of your website, alongside the main index file. The leading dot marks it as hidden, so file managers and FTP clients often filter it out until you switch on an option such as show hidden files. If it genuinely does not exist, your server may be Nginx, which does not use it.

Should I add redirects here or use a plugin?

Both work. A rule in this file is handled by the server before your site's code runs, so it is faster and applies even to files that are not pages. A plugin is easier to manage, keeps a record, and is safer for people who are not comfortable with server syntax. Large permanent mappings usually belong in the file.

My site shows a server error after editing it. What now?

Restore the copy you saved, or rename the file so the server ignores it, and the site should come back immediately. Then reintroduce your changes one rule at a time, testing after each. A single stray character or a directive your host does not permit is enough to break every request, which is why editing without a backup is risky.

Related terms

Found this useful?

Share it, or ask an AI to summarise it

Back to the glossary

Knowing the term is the easy part

Applying it to your own site and budget is the work. Book a call and I will tell you what actually applies to you.