You wouldn't have the issue at all if you set the site definition to use Document paths instead of Site relative paths.
The underlying cause of the problem is the Crate paths relative top setting.
Yes, once the problem exists, the code needs to be edited and the paths changed, but to prevent the problem in the future, change the way the site is set to create paths.