mod_proxy_html revisited

I had a phone call today. From a registered user of mod_proxy_html, looking for help running it with a microsoft sharepoint backend.

His problem appeared at first to be Question 3 in the mod_proxy_html FAQ. But when I finally got a copy of an unfiltered page from him, it turned out to be a variant on it, and one that I could fix for very little effort and negligible runtime overhead.

The page he sent me looked something like

<meta http-equiv=”content-type” content=”text/html; charset=utf-8″>

<html xmlns:…..>
[followed by parseable tag soup]

I ran that through xmllint, and as expected, the output looked similar to that of mod_proxy_html. The parser (correctly) inserts the implied <html> and <head> when it encounters the first bogus <meta>. When it encounters <html> it sees a tag that cannot appear within an HTML page, and its attributes become loose text, which in turn implies <body>. Miraculously, despite the parser now being thoroughly confused, the page displays just fine, apart from that loose text.

OK, now mod_proxy_html already does some body sniffing before starting the HTML parser. Specifically it checks for charset in an XML BOM, XML declaration, or HTML META element. So why not add an optional extra check, to strip out any leading junk and start the parser at the first legitimate element (HTML, HEAD, TITLE or BODY)? That offers an extra little bit of error correction for users.

I hacked it up this afternoon, and will probably update the published mod_proxy_html with it sometime soon.

Posted on October 12, 2006, in apache. Bookmark the permalink. 16 Comments.

  1. I just encountered the issue where mod_proxy_html converts the xmlns portion of to loose text. The HTML I’m dealing is generated by Sakai. I’m going to see if I can’t find where Sakai generates this, but this is a big program, so that could take some doing. If there were any way to not create unexpected text, that would be very nice…

  2. Hi, I have exactly this problem, in the BODY (near to the bottom) there is an additional tag and the parser remove it but the application (sharepoint) “crash”.

    How should I resolve this issue?

    Thanks a lot.

  3. My best suggestion now is to try the dev version, mod_proxy_html 3. This gives you quite a lot more control over how bad HTML is processed, including a specific fix for the problem identified in this blog entry.

  4. Thank you niq

    Can you explain me how to setup version 3 of the mod_proxy_html.c and convert it in

    I have install version 2.5 from a distribution package and I won’t recompile apache.

    Thanks in advance for your indications!

  5. I have another problem:

    mod_proxy_html module convert all html attribute to a lowercase string.

    ctxname in default.aspx become a lowercase string and the app crash;

    How can I solve this problem?

    I’ve tried to add mod_proxy_html dev with apxs but don’t work and I can’t install the dev module.

    Help me please!


  6. here’s an example where the libxml2 parser chokes on the javascript embedded in the head of the page and decides to fix it up by adding extra where it shouldn’t.

    is there an option to tell libxml2 ‘don’t attempt fix it, just match elements in descending order until you have a completed tag’? or, to skip-fixing over certain tags? it seems to mainly get upset on the ‘script’ tag.

    i’m using libxml2-2.6.16-6.. using and as examples, setup in a simple reverse proxy ProxyHTMLMap scenario.

    i really like to speed and compactness of the sax parser. doing pure string search and replaces on the
    entire document is so inefficient.

    hope this makes sense.


  7. I don’t really think a blog comments thread is the right place to resolve rather vague technical issues like these. In any case, neither of the sites you mention serves me any <script>: what they do on the server side is already too broken.

  8. Can anybody help…. I’m trying to configure apache to work as reverse proxy for Sharepoint… But sharepoint maintains absolute url’s in the pages at some places which my apache doesnt resolve and still shows as the actual link… As this is my first time working with apache server i’d to read up a lot to find out about the mod_proxy_html which does this job. After getting this module i added something to my httpd.conf file for replacing the links which still isn’t generating the expected result.

    This is what I added to my conf file in the root
    ProxyHTMLURLMap*) /$1 [R]

    As this is something which is abit urgent, it’ll be nice, if anyone could help.

    Thanks in advance

  9. hello all,
    I managed to setup the reverse proxy using apache… now all the links are rewritten to use my proxy server…
    but the new problem which arises is the same as that mentioned in the first blog here… my meta tag isn’t identified properly… so it is displayed as plain text on my sharepoint site… I’m using the latest version of dated (Oct 10th 2007)… so can any1 tell me what i’ll have to do to make it work fine…
    thanx in advance..

  10. Hi…

    I have problem with mod proxy html 3 where action attribute in form is not get parsed. And some ‘&nbsp;’ the ‘&’ is converted to ‘&amp;’. some of the whitespace get replaced with &nbsp.


  11. HI I also have the same problem with the conversion of ‘&’ to ‘&amp’ and witespaces to &nbsp

    Thanks alot.

  12. Hello All,

    I was also trying to setup apache as a reverse proxy for sharepoint.

    I was successfule in rewriting all the url’s. But I found two errors :
    1) for a listTemplate is null or not an object. (error on the status bar).
    2) certain pages in sharepoint 2003 have nested Html tags. the parser is not able to validate it and displays lose text. Is there anyway we can skip the cheking of any nested html tags?

    A fast response would be appreciated as it is quite urgent.

    Thanks in advance.

  13. Hi,
    when using the mod_proxy_html i noticed when i have an attribute with out a value (i.e. checked, disabled) the filter adds value to it, i.e. disabled=”disabled” and checked=”checked”

  14. Hi,
    did someone find a way to turn off the mod_proxy_html error correction?

  15. best reverse proxy as I believe you can setup in htaccess or apache virtualhost

  16. Thank you for sharing this awesome information

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: