pathPrefix and redirects #27988
Replies: 1 comment 1 reply
-
Hey @JoshuaWalsh I think observation you did:
Is pretty spot on. That's pretty much what redirects as they are now in gatsby are meant to do and it really is to cover cases of moving some page to new URL/slug within context of same
This is a breaking change, so not sure if we can even consider this. Maybe instead there should be toggle (
I'm struggling a bit with this (in terms of understanding what you mean) - for site visitors they should still see |
Beta Was this translation helpful? Give feedback.
-
Hi all, I'm a maintainer of gatsby-plugin-s3. One of the long-standing issues with our project has been support for prefixed sites, you can see this in gatsby-uc/gatsby-plugin-s3#24 and gatsby-uc/gatsby-plugin-s3#208. I'm interested in finally solving this once and for all, but I'm running into some philosophical questions about prefixing.
In my view there are two kinds of prefix:
a client-facing prefix is one that appears in the URL: e.g. https://example.org/**blog/**my-blog-post
a storage prefix is one that applies to the file system on the server: e.g. /var/www/example.org/**blog/**my-blog-post/index.html
In the simplest case these are both the same. But there are scenarios where you might want to have a storage prefix without any client-facing prefix, such as if you want to store multiple versions of your site and use something like Lambda@Edge to select one for AB testing. Having a client-facing prefix without a storage prefix is also something that's supported by a lot of server software, such as via nginx's location block. Maybe there are even some cases where someone would want to use a different client-facing prefix and storage prefix.
Gatsby's
pathPrefix
appears to be intended to cater for client-facing prefixes. Output files are placed inpublic/
without any prefix.In
gatsby-plugin-s3
we provide a plugin optionbucketPrefix
which allows for specifying a storage prefix.The issue we are experiencing is that while Gatsby does not prepend
pathPrefix
to output files, Gatsby does prependpathPrefix
to thefromPath
of redirects. This behaviour is covered by tests,gatsby/packages/gatsby/src/redux/__tests__/redirects.ts
Lines 101 to 109 in 57ca573
gatsby/packages/gatsby/src/redux/__tests__/__snapshots__/redirects.ts.snap
Lines 171 to 181 in 57ca573
bucketPrefix
to redirects.It is my opinion that
pathPrefix
should be prepended totoPath
of redirects, but not tofromPath
. ForfromPath
, the prefixing should be handled by whichever plugin is deploying the redirect.Another option would be for us to stop prefixing
bucketPrefix
for redirects and just rely on thepathPrefix
instead. But this doesn't work as expected whenpathPrefix
andbucketPrefix
have different values. Consider a case where someone is hosting two versions of their site out of the same bucket, and using Lambda@Edge to serve each one to different clients for AB testing.public/index.html
gets uploaded toa/index.html
andb/index.html
thanks tobucketPrefix
, whilepathPrefix
is left blank so the user still just visits https://example.org/ and not https://example.org/a/. The developer wants to add a redirect on site A. If we don't applybucketPrefix
, the redirect will be pushed toold-page
, when the user really wants the redirect pushed toa/old-page
.Please let me know your thoughts.
Thanks,
Josh
Beta Was this translation helpful? Give feedback.
All reactions