http://www.perlmonks.org?node_id=50221


in reply to LWP strikes again!

If you read the html spec at W3C you can find out this:

In HTML, links and references to external images, applets, form-processing programs, style sheets, etc. are always specified by a URI. Relative URIs are resolved according to a base URI, which may come from a variety of sources. The BASE element allows authors to specify a document's base URI explicitly.

When present, the BASE element must appear in the HEAD section of an HTML document, before any element that refers to an external source. The path information specified by the BASE element only affects URIs in the document where the element appears.

So the simplest method is:

my $content = $res->content; $content =~ s#</head>#<base href="http://perlmonks.org"></head>#; print $content;
Otherwise you would need to filter the source with one of the HTML:: parsers and make all urls absolute.