Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

inject html using apache

Tags:

html

apache

I have a portal that is under a virtual host in Apache. All lot of its .css and .js is generated dynamically by the underlying tomcat web application. What I want to do is inject some of my own .css and .js into the mix before it is served. I think I need something like mod_rewrite but for html.

I know I could try to piggyback onto some resource reference that is used on every page and use mod_rewrite that way, but that is hard to do and I need my css to be applied last.

Tell me there are some magic beans for this. I just need to inject a couple scripts and styles right at </head>.

like image 455
Mark Robbins Avatar asked Jul 22 '26 04:07

Mark Robbins


1 Answers

I haven't used it before, but it looks like mod_ext_filter could do this

By looking at the example, you could try the following Perl script

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

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

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

After I posted this, I noticed someone recommended https://serverfault.com/questions/46449/how-to-inject-html-code-into-every-delivered-html-page. mod_proxy_html and mod_sed looks good

like image 123
user1175332 Avatar answered Jul 23 '26 18:07

user1175332