Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add comment in apache httpd.conf not as a complete line?

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?

like image 705
cytsunny Avatar asked Apr 29 '18 07:04

cytsunny


People also ask

How to comment out an Apache config block?

But, if you're using vim, here's a tip (from my co-worker) to comment out a Apache config block. Put the cursor under the D character at the opening <Directory ...> line and type the following:

Can I edit the Apache httpd configuration file?

Although the Apache httpd configuration file is easy to edit, it will prevent the webserver from running if you mess up its syntax. The following are some tips to keep in mind when editing the configuration files.

Why are there comments in a configuration file?

This is a simple process, but may not be self-explanatory to people that don’t understand the file’s structure. The interpreter ignores lines marked as comments, which are only to aid humans in understanding the file. Because of this, comments can be used to disable or enable configuration options in configuration files.

How do I comment out a line in a file?

Or, to “comment out” a line, add a # character to the start of the line. (Note that some languages have different comment formats, so this may not be true if you’re working with a source code file.) For example, let’s say you have a file with the following text:


2 Answers

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 ...

like image 176
Juan Mellado Avatar answered Oct 04 '22 07:10

Juan Mellado


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> 
like image 20
Sheetal Mohan Sharma Avatar answered Oct 04 '22 08:10

Sheetal Mohan Sharma