38

In an apache conf file, if a line is start with #, that line is counted as comment. For example,

#This is a comment line
#And then the following is some real settings:
AllowOverride None

However, this is not allowed.

#And then the following is some real settings:
AllowOverride None #A comment that starts in the middle of line

Is it possible to starts a comment in the middle of the line? And if yes, how?

cytsunny
  • 4,838
  • 15
  • 62
  • 129

3 Answers3

47

The documentation states that it is not possible:

... Lines that begin with the hash character "#" are considered comments, and are ignored. Comments may not be included on the same line as a configuration directive ...

Juan Mellado
  • 14,973
  • 5
  • 47
  • 54
  • I wonder... can a comment be indented? As in, if the hash character is preceded by whitespace, is this still considered to be a "line that begins with the hash character"? – osullic Feb 10 '21 at 11:08
  • @osullic yes it can be indented. – jeanpic Oct 14 '21 at 07:52
4

I believe only # is parsed as there is no real need for it. But if you really need you can use IfDefine block, which will be ignored unless a matching variable has a definition.

<IfDefine myexisterenceIsForJustAComment>
...
</IfDefine>

Look at discussion at : https://bugzilla.redhat.com/show_bug.cgi?id=1349546

Not sure if these are supported in latest versions (< httpd-2.2.15-53) but you can try below which was supported in earlier versions. You may be in luck if you are on older version.

In earlier/older versions of Apache, I remember it was okay to include a comment at the end of a line (wrapped in double quotation marks), like so:

<Limit GET >
    Order Allow,Deny
    Allow from all
    Deny from xxx.xxx.xxx "# I am in inline comment"
</Limit>
Hendy Irawan
  • 20,498
  • 11
  • 103
  • 114
Sheetal Mohan Sharma
  • 2,908
  • 1
  • 23
  • 24
1

Apache interprets its conf files line by line. And it considers a line starting with # as a blank line (or line break) and skips the line. Also it doesn't have a symbol to indicate comments because conf files have many special symbols, which might let them to disable middle-line comment.

Perfect
  • 1,616
  • 1
  • 19
  • 27