How to make sure relative URL works when site is not on root domain?

Make use of the functions wordpress offers to determine paths and URLs – see Determining Plugin and Content Directories. For example use:

You find more information on the linked codex page about determining directories.


Edit: In response to the comment.

This is how I’d do it:

function mytheme_get_theme_mods() {
    $tpl_dir_pth = get_template_directory();
    $defaults = array(
        'mytheme_header_logo' => $tpl_dir_pth . '/img/logo.png',
        'mytheme_footer_logo' => $tpl_dir_pth . '/img/footerlogo.png',
        'mytheme_middle_image' => $tpl_dir_pth . '/img/middleimg.png'
    );

    return $defaults;
}

Of course I don’t know if the absolute path actually is what you want.