import posixpath


def make_relative_url(base, target):
    """Returns a relative URL from base to target."""
    if base == '/':
        depth = 0
        prefix = './'
    else:
        depth = ('/' + base.strip('/')).count('/')
        prefix = ''

    ends_in_slash = target[-1:] == '/'
    target = posixpath.normpath(posixpath.join(base, target))
    if ends_in_slash and target[-1:] != '/':
        target += '/'

    return (prefix + '../' * depth).rstrip('/') + target