How to comment out whole sections of a .htaccess file?

Strictly speaking, .htaccess files only allow single-line comments: an hash character (#) at the beginning of a line lets the parser know that line should be ignored, i.e.:

# this is a comment in an .htaccess file and many other scripting languages

However, from a practical perspective it is possible to wrap any number of contiguous lines in an IF block (available from Apache 2.4). This effectively disables the lines within the block. For example:

<IF "false">
...disabled directives...
</IF>

That been said, a multi-line comment in many programming languages would allow more or less any content within it, i.e. plain english rather than viable code. Conversely, the content of an IF block as mentioned above must be composed of proper .htaccess directives and regular single-line comments - an http 500 error will be generated otherwise.


Expanding and giving an example of Manu3D answer, you can encapsulate the comment content into a FilesMatch directive and use an improbable filename for the match.

<FilesMatch "index-sbrubles123land9897Brazil\.(php?)$">
    #commented content here
</FilesMatch>

But, I would avoid to use many comments and specially this "faux multiline comment" technique in a production environment. I think the less time Apache spend parsing .htaccess files, the better (less prone to errors).

And don't forget that you can't use text or any invalid apache syntax inside this false comment, anyway. It would be helpful to temporarily or conditionally disabling other directives, but not to comment text.