• Pular para navegação primária
  • Skip to main content
  • Home
  • Sobre/About
  • Projetos
  • Fotografia
  • Blog
    • Feed/RSS
  • Boletim/Newsletter
    • Humanist Techology Newsletter
    • Boletín Tecnología Humanista
    • Boletim Tecnologia Humanista

Celso Bessa (sɛwsʊ bɛ:sa)

Prefiro construir pontes a muros

Você está em: Home / blog / tecnologia / Hack: Apache Faux Multiline Comments

Hack: Apache Faux Multiline Comments

11 outubro, 2017 por Celso Bessa

sample code for Faux Multine Comments on Apache .htaccess files

A quick hack for web developers: how to use FilesMatch for a faux multiline comment.

As you may or may not now, Apache doesn’t have a native clean way to make use of multiline comments. You got to comment each line with a # symbol (i.e hash, sharp, number, whatever). Which is tedious and take a long time in certains cases.

[Para versão em português, clique aqui]

As an example, this is one snippet of HTML 5 Boilerplate .htacces files

# Serve resources with the proper media types (f.k.a. MIME types).
#
# https://www.iana.org/assignments/media-types/media-types.xhtml
# https://httpd.apache.org/docs/current/mod/mod_mime.html#addtype

# Serve resources with the proper media types (f.k.a. MIME types). # # https://www.iana.org/assignments/media-types/media-types.xhtml # https://httpd.apache.org/docs/current/mod/mod_mime.html#addtype

Faux Multiline Comments

The good news is that you can simulate multiple lines comments in some limited situations. It won’t allow for long texts, but it allows you to temporarily disable a series of directives for when you are developing/staging, etc

You just need to use FilesMatch to encapsulate what must be commented and trying to match an improbable name (e.g. index-sbrubles123land9897BrazilQueerMuseum.php)

Something like that

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

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

As stated, is limited, but it can helps a lot while developing.

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 (and less trouble prone).

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.

sample code for Faux Multine Comments on Apache .htaccess files

Arquivado em: tecnologia Marcados com as tags: Apache, development, FilesMatch, H5BP, hack, htaccess, HTTP, servers, webdevelopment

Sobre Celso Bessa

Prefiro construir pontes à muros. Cidadão, tecnologista de interesse público, consultor em cibersegurança, Media Democracy Fund fellowship alumni e fundador da Tecnologia Humanista.

Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (exceto fotografias com produto de terceiros ou pessoas)
Otimizado pela WoWPerations e hospedado na Digital Ocean
(Assinando Digital Ocean através deste link do programa indicação, você ganha crédito de 100 dólares para serem utilizados em até 60 dias, e eu ganho uma pequena comissão)