Instead of modifying the relative URLs everywhere, wouldn't it be better to just add a <base href="http://base.url/here/"/> tag in the html <head> section?
You could do it either using a regex (just add it before the </head>) or parse the html and add it.
If you want to improve, be content to be thought foolish and stupid. -- Epictetus