Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

You can use # to comment out individual lines. Is there a syntax for commenting out entire blocks?

I've tired surrounding the block (specifically a <Directory> block) with <IfModule asdfasdf>...</IfModule>, but that didn't work.

share|improve this question
add comment

4 Answers

up vote 18 down vote accepted

I came across this post from a Google search for "Apache block comment". Later, I discovered a non-perl, non-import solution from Apache's core documentation (although I'm sure this is very non-intended practice). From the core documentation for Apache 2.0 http://httpd.apache.org/docs/2.0/mod/core.html, you can see that the tag <IfDefine> will handily ignore statements when the parameter you specify does not exist:

<IfDefine IgnoreBlockComment>
...
</IfDefine>

So that'll successfully "comment" out the statements in between.

share|improve this answer
add comment

I am not sure if apache has such type of comments.

As a workaround, you can use include statement in the following way:

yourfile.conf:

<Directory>
  ....
</Directory>

When you want to comment this block, you just need to comment out the include line:

#include yourfile.conf
share|improve this answer
    
Sad :( I've heard NGinx has better easier configuration. –  ripper234 Jan 2 '12 at 10:39
2  
Comments aren't configuration. A good text editor will allow you to quickly add stuff to multiple lines, too. In Textmate, it's Option+Drag. –  ceejayoz Jan 2 '12 at 18:57
add comment

AFAIK, Apache doesn't support this.

But, if you're using vim, here's a tip (from my co-worker) to comment out a Apache config block.

For instance, given this snippet:

<Directory "a/b/c">
    SetEnvIf X-Forwarded-For ^x\.y\.z\.t let_me_in
    Order allow,deny
    allow from env=let_me_in
    ErrorDocument 403 http://google.com
</Directory>

Put the cursor under the D character at the opening <Directory ...> line and type the following:

V/Dir -> Enter

followed by:

:s/^/#/ -> Enter

  • V - to highlight the current line
  • /Dir - selects the whole block
  • :s/^/#/ - puts a # at the begin of each line
share|improve this answer
1  
I think it's easier to just go in Visual Block mode on the opening tag, scroll down to the closing tag, and then do shift-I (big i) # Esc. –  Janus Troelsen Apr 16 '13 at 20:41
add comment

You can't do it directly but here's a hacky work-around:

<IfModule mod_perl.c>
  <Perl>
=pod
  Multi-line
  comments
  go
  here
=cut
  </Perl>
</IfModule>

It expands upon your "IfModule" approach above but it leverages the mod_perl <Perl> block and Perl's POD syntax to create a block of documentation.

It should work whether mod_perl is loaded or not.

share|improve this answer
2  
Loading and embedding Perl into Apache just so you can comment out a block is a bad idea. –  bahamat Jul 5 '12 at 17:47
1  
@bahamat Agreed. However, perhaps you missed the part that says that you don't need to load mod_perl to use this. If you find that this causes an error when mod_perl isn't loaded let me know. It didn't cause an error for me. –  benrifkah Jul 5 '12 at 18:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.