the Settings > General > Advanced > File Links Are… is set to one of the bottom two items
in that case code-path to generate relativeCommonFilesFolderName was utilizing RWExportParameters pluginCommonPath method. in this case the this method returns a URL prefixed with the site address -- which is obviously not correct for a relative URL.
the solution that seems to satisfy all corner cases is to use stacks private relativedocroot method as the base URL for publish
but in preview to continue to use pluginCommonPath to identify the cases where the files directory shifts based on shared folders and custom naming.
in edit mode this entire mess is bypassed and direct file urls are provided -- but it isn't often used since Php is the common use case which is moot in Edit mode.
in that case code-path to generate relativeCommonFilesFolderName was utilizing RWExportParameters pluginCommonPath method. in this case the this method returns a URL prefixed with the site address -- which is obviously not correct for a relative URL.
the solution that seems to satisfy all corner cases is to use stacks private relativedocroot method as the base URL for publish
but in preview to continue to use pluginCommonPath to identify the cases where the files directory shifts based on shared folders and custom naming.
in edit mode this entire mess is bypassed and direct file urls are provided -- but it isn't often used since Php is the common use case which is moot in Edit mode.