mod_line_edit is a general-purpose filter for text documents. It operates as a simple on-the-fly line editor, applying search-and-replace rules defined in a configuration or .htaccess file.
Unlike most of WebÞing's filter modules, it is not markup-aware, so it is not an optimal choice for processing HTML or XML, though it may nevertheless be used with caution (and may be far better than semi-markup-aware options such as mod_layout).
For non-markup document types such as plain text, and non-markup Web documents such as Javascript or Stylesheets, it is the best available option in the absence of a filter that parses any relevant document structures.
mod_line_edit is written for performance and reliability, and should scale without problems as document size grows. mod_line_edit is fully compatible with Apache 2.0 and 2.2, and all operating systems and MPMs.
LoadModule line_edit_module modules/mod_line_edit.so
The module implements a single output filter named line-editor
.
Insert it in the filter chain using the standard filter directives,
e.g. to rewrite all text documents:
FilterProvider textedit line-editor resp=Content-Type $text/
FilterChain textedit
or, for backward compatibility with Apache 2.0:
AddOutputFilter line-editor .txt .css .js
or
SetOutputFilter line-editor
SetEnv LineEdit "text/plain;text/css;text/javascript"
The LERewriteRule
directive defines search-and-replace rules.
Both simple text and regular expression search and replace are supported.
mod_line_edit normally applies its edits line-by-line. This avoids the risk of missing a pattern to be matched because it is spread over more than one chunk of data when it reaches the parser, without having to resort to the performance and scalability limitations of loading an entire document into memory.
If the LineEdit environment variable is set, it controls Content Types that will be filtered. This enables it to filter selectively on content-type in a proxy with Apache 2.0. Just set the variable to a list of content types, and mod_line_edit will leave other types untouched.
Example: to filter plain text and javascript, but leave other types alone:
SetEnv LineEdit "text/plain;text/javascript"
This also works with Apache 2.2, but is of course unnecessary there.
LELineEnd UNIX|MAC|DOS|NONE|ANY|CUSTOM [char]
This tells the parser what characters in the text to interpret as line-endings:
\n.
\r. Note that modern MacOSX is Unix-based.
\r\n.
\r\ntreated as one, not two, linebreaks). This is the default.
When you use LELineEnd Custom
, you must specify a second
single-character argument, which is the character to split the input on.
For all other LELineEnd
options, any second argument will
be ignored.
LERewriteRule from-pattern to-pattern [flags]
This directive defines a search-and-replace edit rule that will be applied to the text.
LELineEnd
None
).mod_line_edit.c source code is available under the GNU General Public License (GPL). As with other opensource modules, we can consider alternative licenses by request.
Registered Users may request binaries for any available platform.
Dec. 26th 2005: the first public release of mod_line_edit is version 0.9.2
June 12th 2006: added capability to interpolate environment variables in rewrite rules. Bumping version to 1.0 because 0.9 has proved stable over six months in the wild.