I've been there, and spent a long time trying to figure out what to do to fix that problem too. I came to the conclusion to use the <base> tag in your HTML document head tag.
EDIT: As for your offline testing, I usually use a conditional php statement based on $_SERVER['SERVER_NAME'] whether to include
<base href="http://localhost/" />
and that way, I never have to change anything in my code when I upload my pages to my server, because the PH conditional just picks out which base tag to use.
<base href="http://www.myserver.com/" />
I've switched careers...
I'm NO LONGER a scientist,
but now a web developer...