If you start your image or file path with /, then it starts from the document root, for example:
You're on this page:
www.domain.com/path/to/my/file.php
Your like looks like this:
<a href="/basefile.php">my link</a>
Brings you to:
www.domain.com/basefile.php
Image src="" work the same way. That what you needed?
You could also prepend all your image tags with a PHP variable, $_SERVER['HTTP_HOST'] if you wanted...