Hi everyone, I have followed the great guide on how to use proxies to link a section of one repository to another. Everything works as expected but I have an issue with relative paths.
Here is the structure:
Repository A
A.netlify.com
Contains my main website with custom domain (x.com
)
Has a proxy that rewrites x.com/blog
to B.netlify.com/blog
Repository B
B.netlify.com
Contains my static blog page.
I have deployed the blog to the subfolder /blog
The problem is with the assets on Repository B.
Solution 1: Using absolute paths
If I use absolute paths for all the assets (x.com/blog/image.jpg
) everything works fine. BUT if someone happen to visit B.netlify.com/blog
directly he will get CORS issues as B.netlify.com
will try to access assets on x.com
I’m aware that nobody is supposed to be visiting the repository directly, but I don’t like to leave a broken page around.
Solution 2: Using relative paths
If I use relative paths for all the assets (./image.jpg or image.jpg) it works only when visiting the blog using a trailing slash x.com/blog/
. If the relative paths includes the subfolder (./blog/image.jpg or blog/image.jpg) it works only when visiting the blog without a trailing slash x.com/blog
I’d expect x.com/blog
to be redirected to x.com/blog/
or the other way around, but for some reasons it doesn’t work that way. I can’t find a solution that works in both cases (except absolute paths).
So my question is: what would be the best approach for this kind of proxy issues?
Many thanks!