Download a dated copy of .htaccess before anyone edits it, send changes to whoever manages the server, change one thing at a time and test. If every page shows an error, put the copy back.

Every page, one error

Someone at a furniture store wants the old winter sale page to send visitors to the new spring catalogue. A forum post offers a one-line redirect, and they paste it into a file on the server.

Seconds later every page shows the same message: Internal Server Error. Home page, product pages and contact form all fail together.

The line was meant to affect one address. It stopped the whole site because of where it went: the .htaccess file.

A small file the server reads constantly

On the Apache web servers behind a great deal of shared hosting, .htaccess is a short text file of instructions. The dot at the start of its name hides it in many file managers and FTP programs.

The server reads it on every request for any page in its folder or the folders below. When the file sits in the main folder, that means every page on the site.

When the server meets a line it cannot understand, it does not skip it. It refuses the request and returns an error, page after page, until the line is fixed or removed.

What the file controls

Small as it is, the file often holds instructions the site depends on:

Many of those lines were added years ago by different people, and few are labelled. Deleting one that looks unfamiliar can break something no one remembers depending on it.

Why a pasted line can break it

A forum answer is written for the writer's server, not yours. The same line can be harmless there and fatal here.

It may rely on a server module yours does not load, or use an instruction your host does not allow in this file.

It may set PHP options on a server where PHP runs separately from the web server, which then treats those lines as errors, or be written for another kind of web server altogether.

A curly quote, a missing space or a stray character copied with the line is enough on its own.

Lines a content system depends on

WordPress, Joomla and similar systems rely on their own rules in the file so that their page addresses work. WordPress marks its section with comment lines and rewrites everything between them when its address settings are saved.

A change pasted inside that section can vanish the next time someone saves those settings. A rule pasted below it may never run, because the system's rules catch the request first.

Your own rules belong outside it, usually above, each with a comment saying what it does.

A worked example

A precast concrete plant near Penticton makes septic tanks, retaining wall blocks, utility vaults and custom pieces for contractors. Its website has a form for sending drawings with a quote request.

Large drawing files kept failing, and someone in the office found a forum post with two lines to raise the upload limit. Pasted into the .htaccess file, they took down every page, the quote form included.

Contractors began phoning to ask whether the site had been shut down. The web developer read the server's error log, which said plainly that the server did not recognise the two lines.

On that host, PHP ran separately from the web server, so the upload limit had to be set in the PHP settings the host provides. The developer restored the saved copy and raised the limit there.

The file now opens with a comment asking that changes go to the developer, who saves a dated copy before each edit.

The limit now lives where that server actually reads PHP settings, and the file contains only lines the server understands, each with a note saying why it is there.

Why it belongs with whoever manages the server

Whoever manages the server knows which modules it loads, which instructions the host permits and how PHP runs. That is most of what decides whether a line works.

They can also read the error log, which names the line and the reason. The error on screen says only that something failed; the log says what.

And they can try a change on a copy of the site first, rather than on the one customers are using.

A change made safely

Before editing, download the current file and save it with the date in its name. Change one thing at a time, so a failure points straight at its cause.

After each change, load the home page, a few inner pages, any form and any old address that should redirect. If anything fails, put the saved copy back at once.

Above each rule, add a comment recording its purpose, who asked for it and when. A line beginning with a hash sign is ignored by the server and read by the next person.

If the site is already down

Put the saved copy back. Without one, the host can usually restore the file from its backups, so that is the first call to make.

Renaming the file brings the pages back, but it also switches off everything the file did: redirects, clean addresses and any password protection on private folders. Treat it as a stopgap of minutes, not a fix.

The counter-case

A small site of plain pages may have no .htaccess file at all, or one that has not changed in years. For it, the file is not a daily concern.

Some hosting does not let customers edit the file, and some servers do not read it. There the same settings live elsewhere, under the host's control.

But wherever the file exists it governs every page, and no line from a forum belongs in it without a copy kept and someone who can read the error log.

Changes made with a copy kept

  1. Find the file, with hidden files shown.
  2. Download a dated copy before any edit.
  3. Send the change to whoever manages the server.
  4. Keep your rules outside the content system's section.
  5. Change one thing at a time.
  6. Test the pages, forms and old addresses.
  7. Label each rule with a comment.

Step two keeps an outage short. With the previous file saved, getting the site back means putting one file back, not working out from memory what changed.

Another small setting with a large effect, a mail record still pointing at a former host, is the cause in half the email still arriving at the old mail server.


Frequently asked questions

What is the .htaccess file?

A small text file of instructions that Apache web servers read on every request. It can hold redirects, rewrite rules, password protection, error pages and other settings.

Why does one wrong line take down every page?

The server reads the file for every page in its folder and below, and a line it cannot understand makes it refuse the request rather than skip the line.

Why does a rule from a forum fail on my site?

It was written for another server. Yours may lack the module it needs, forbid that instruction in this file, or run PHP in a way that rejects such settings.

How do I get the site back quickly?

Put back the copy you saved before the edit. Without one, ask the host to restore the file from its backups. Renaming the file is only a stopgap.

Is renaming the file safe?

It brings pages back but switches off everything the file did, including redirects, clean addresses and password protection on private folders. Use it for minutes, not days.

Can WordPress overwrite changes to the file?

Yes. WordPress rewrites its own marked section when its address settings are saved. Put your own rules outside that section, usually above it, with a comment.

West Coast Media Solutions Inc. provides web design, web development, hosting, digital marketing, and business consulting to organisations across Canada, drawing on more than twenty-five years in the field.

Every page showing a server error?

Tell us which site is down, and we will read the error log, restore a working file and keep a dated copy.

Start a Conversation