def rebase_path(from_root_path, to_root_path, path):
    """
    Rebase the path to a new root path.
    :type path: pathlib.Path
    :type from_root_path: pathlib.Path
    :type to_root_path: pathlib.Path
    :rtype: pathlib.Path
    >>> source = Path('/tmp/from/something')
    >>> dest = Path('/tmp/to')
    >>> rebase_path(source, dest, Path('/tmp/from/something/test.txt'))
    PosixPath('/tmp/to/test.txt')
    >>> rebase_path(source, dest, Path('/tmp/other.txt'))
    PosixPath('/tmp/other.txt')
    >>> rebase_path(source, dest, Path('other.txt'))
    PosixPath('other.txt')
    >>> dest = Path('/tmp/to/something/else')
    >>> rebase_path(source, dest, Path('/tmp/from/something/test.txt'))
    PosixPath('/tmp/to/something/else/test.txt')
    """
    if from_root_path not in path.absolute().parents:
        return path

    relative_path = path.absolute().relative_to(from_root_path)
    return to_root_path.joinpath(relative_path)