使用apache注入html

时间:2012-01-24 18:38:53

标签: html apache

我有一个位于Apache虚拟主机下的门户。它的所有很多.css和.js都是由底层的tomcat Web应用程序动态生成的。我想要做的是在服务之前将一些我自己的.css和.js注入混合中。我想我需要像mod_rewrite这样的东西,但对于html。

我知道我可以尝试搭载一些在每个页面上使用的资源引用并以这种方式使用mod_rewrite,但这很难做到,我需要最后应用我的css。

告诉我这里有一些神奇的豆子。我只需要在< / head>。

注入几个脚本和样式

1 个答案:

答案 0 :(得分:0)

我之前没有使用它,但看起来mod_ext_filter可以做到这一点

通过查看示例,您可以尝试以下Perl脚本

#!/usr/local/bin/perl -w
use strict;

my $extraCode = "<script src=\"http:/...\"></script>";

while (<STDIN>) {
    s/<\/head>/$extraCode<\/head>/i;
    print;
}

发布此内容后,我发现有人推荐https://serverfault.com/questions/46449/how-to-inject-html-code-into-every-delivered-html-page。 mod_proxy_html和mod_sed看起来不错