3

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>.

1

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

I ended up using mod_substitute and: AddOutputFilterByType SUBSTITUTE text/html Substitute "s|</body>|<script type=\"text/javascript\" src=\"http://blah.js\"></script></body>|ni" Though this doesn't work for some of my portals, but thankfully I found out how to hack them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.