htaccess

An htaccess file, written .htaccess, is a plain text file that gives a web server instructions for the folder it sits in and every folder below it. Apache reads these files, and so do servers built to behave like Apache, such as LiteSpeed. Most WordPress sites have one in their main folder, because WordPress writes its permalink rules there.

How an htaccess redirect works

When a browser asks for a page, the server checks this file before it answers. If a rule says the old address has moved, the server replies with a 301 status and the new address. The browser then asks for the new page and shows it, and the visitor rarely notices the extra step.

A redirect like that can be one line long.

Redirect 301 /old-page/ /new-page/

Search engines follow the same 301. Over time, they swap the old address for the new one in their results, and links pointing at the old page usually count towards the new one.

Other jobs the file does

Redirects are the most common use, but there are plenty of others. It can send every visit to the HTTPS version of a site, block access to a private folder, switch on compression, and tell browsers how long to keep images in their cache. Security and caching plugins often add their own blocks of rules too. Each rule covers its own folder and the ones below it, so a file in a subfolder can override the main one.

When htaccess changes go wrong

The server reads the file on every request, so one typing error can take the whole site down, usually with a 500 error. Redirect rules can also clash with each other. Visitors then get sent round in a loop, or through a chain of several hops before they reach the page.

It's always worth saving a copy of the working file before you change it. Bear in mind that not every server uses these files. Nginx ignores them, and platforms like Shopify, Wix, and Cloudflare Workers set redirects in their own settings.

Reading old server rules when a site moves to us

Jaden manages our servers and hosting, so he deals with these files whenever a website moves over to us.

When a site moves onto our servers, its old redirects are one of the first things we check. They tend to pile up over the years, so we carry over only the ones the site still needs.
JadenLead Developer, Bird Marketing
  1. Moving your website to our servers involves more than the site itself, so we check the services around it first. Each stage then runs as a tracked job that can be undone if needed.

  2. A single robots.txt line can block a whole folder, and long redirect chains waste the visits Googlebot makes to your site.

More technical SEO glossary terms

These technical SEO glossary terms cover crawling, indexing, redirects, sitemaps, structured data and page speed. Each definition shows the idea in a diagram and gives a practical example, so developers, marketers and site owners can talk about the same fix in the same words.