keepcalculator

06 Numbers and Powers

Enable Disable Apache Boolean Values Explained

Card No. 06·86421 · Updated · Standard formula, shown below

Apache configuration directives that accept boolean values are turned on or off with the words On and Off (case-insensitive), not with true/false or 1/0. This article explains how those boolean flags work, where they appear, and how to set them correctly in httpd.conf, .htaccess, and virtual host blocks.

What Are Boolean Directives in Apache?

A boolean directive is a configuration option that has only two valid states: enabled or disabled. Apache’s core module and many third-party modules use these flags to control features like directory indexing, symbolic link following, CGI execution, and SSL enforcement. The official documentation consistently lists the syntax as Directive On|Off, which means you must supply exactly one of those two words.

Common examples include:

  • Options Indexes – the Indexes keyword itself is a boolean toggle inside the Options directive.
  • FollowSymLinks – another Options keyword that controls whether Apache follows symbolic links.
  • ServerSignature – shows server version on error pages when On.
  • EnableSendfile – toggles the sendfile optimization.
  • RewriteEngine – turns the mod_rewrite engine on or off.

Each of these accepts either On or Off. No other value is valid, and Apache will fail to start or return an error if you use something else.

How Apache Parses Boolean Values

Apache’s configuration parser reads the directive name, then expects the next token to be the argument. For boolean directives, the parser compares the argument against the strings On and Off in a case-insensitive manner. So on, ON, Off, and OFF all work. However, the parser does not accept numeric values like 1 or 0, nor the words true or false. If you try those, you’ll get a configuration syntax error when you run apachectl configtest or try to restart the service.

Some directives that look boolean are actually not. For example, LogLevel takes a word like warn or debug, and KeepAlive accepts On or Off but also has a separate MaxKeepAliveRequests directive. Always check the specific directive’s documentation to confirm it is a true boolean.

Where to Set Boolean Directives

You can place boolean directives in several contexts, depending on the directive’s scope:

  • Server-wide – in the main httpd.conf file, outside any container, affects the whole server.
  • Virtual host – inside a <VirtualHost> block, overrides the server-wide setting for that host.
  • Directory – inside <Directory>, <Location>, or <Files> blocks, applies only to matching URLs or files.
  • .htaccess – if AllowOverride permits it, you can set boolean directives in per-directory files.

For example, to enable directory indexing only for a specific folder, you might write:

<Directory "/var/www/html/downloads">
    Options Indexes FollowSymLinks
</Directory>

Here, Indexes is effectively On for that directory, while the rest of the site might have it Off.

How to Choose On or Off

The right value depends on what the directive controls and what behavior you need. For security-sensitive options, the safer default is usually Off. For example:

  • Options -Indexes (or Options Indexes with a minus sign) turns off directory listing, which is recommended on public web servers.
  • FollowSymLinks should be Off unless you specifically need symlinks and understand the security implications.
  • ServerSignature Off hides Apache version details from error pages.

For performance features like EnableSendfile, the default is usually On, but you may need to turn it Off if you encounter issues with network file systems or certain virtual machine setups.

Common Mistakes and How to Avoid Them

One frequent mistake is using True or False because that’s how other software configures booleans. Apache will reject these with an error like:

Invalid command 'True', perhaps misspelled or defined by a module not included in the server configuration

Another mistake is forgetting that Options uses a plus or minus sign to add or remove settings relative to inherited options. For example, Options +Indexes adds indexing, while Options -Indexes removes it. Without a sign, the Options directive replaces the entire set of options for that directory, which can unintentionally disable other settings.

Also, be careful with the order of directives. In Apache, the last setting wins for the same context, but settings in more specific contexts (like a <Directory> block) override less specific ones (like the server-wide setting).

Testing and Troubleshooting

After changing any boolean directive, always test the configuration before restarting:

  1. Run apachectl configtest (or httpd -t) to check for syntax errors.
  2. If the test fails, review the exact line number in the error message.
  3. Restart Apache with systemctl restart apache2 (Debian/Ubuntu) or systemctl restart httpd (RHEL/CentOS).
  4. Verify the behavior by checking the site or using curl to see if headers or content changed.

If a directive doesn’t seem to take effect, check that the module providing it is loaded. For example, RewriteEngine requires mod_rewrite to be enabled. Also, confirm that AllowOverride in the server config permits the directive in .htaccess files.

Frequently Asked Questions

Can I use 1 or 0 instead of On/Off?

No. Apache’s boolean directives only accept the literal words On or Off. Numeric values like 1 or 0 are not recognized and will cause a configuration error.

Is the case important?

No, the parser is case-insensitive. on, ON, and On all work. The convention is to use On and Off with a capital first letter, but it’s not required.

What does Options -Indexes mean?

The minus sign before Indexes means remove that option from the current set. So Options -Indexes disables directory listing. Without a sign, Options Indexes would set the options to exactly that, ignoring inherited options.

Why does my .htaccess boolean directive not work?

First, check that AllowOverride is set to All or includes the relevant module (like FileInfo for mod_rewrite). Second, confirm the directive is allowed in .htaccess context. Some directives are only valid in server or virtual host context.

Can I set a boolean directive per URL?

Yes, you can use <Location> or <Files> blocks to apply boolean directives to specific URLs or filenames. For example, <Location "/private"> can have Options -Indexes.

What happens if I misspell On or Off?

Apache will treat the misspelled word as an invalid argument and fail the configuration test. The error message will point to the exact line, so you can fix it quickly.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →