I'm connecting to Alfresco via webDAV because Alfresco 5 has dropped support for SOAP and so the Alfresco repository plugin no longer works. In doing this I have encountered exactly the same issue as you, whereby the originating server domain is being stripped out and replaced by the Moodle domain. Given that my instances of Moodle and Alfresco reside on different servers this is obviously breaking webDAV links.
This behaviour appears to be an unintended consequence of this bugfix (MDL-37014). This fix was applied to the file https://github.com/moodle/moodle/blob/master/repository/webdav/lib.php. Lines 123-125 appear to have been added to facilitate a fix to this 'bug'. The problem is that this 'fix' has actually broken webDAV links.
I have no idea what side-effect commenting out these lines will have. I will obviously try this and see what happens but this is not itself a fix because unless core Moodle is updated correctly I will have to continuously re-apply this fix with every upgrade (and face the possibility of breaking Moodle because of un-intended future side-effects) or simply never upgrade.
Perhaps a Moodle developer would like to comment?