-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
301 Redirect #208
Comments
Your config looks fine to me. Could you please look in |
Thank you for your Reply :) i can see the file you mentioned with 203 object as the following
|
also i am doing Gzip to my build like this , not sure if it has any side effect . ps: i tried without this code as well and still not working (return 404 when i try to open an old url that must redirect to new url )
|
What CDN are you using? How do you make the client load the .gz/.br files? Your gzipping code should not break anything, but it won't include the redirect objects (and even if it did, they wouldn't be uploaded with the correct metadata). If you are using something like Lambda@Edge to rewrite requests to include .gz or .br, these requests will not hit the redirect object and would result in a 404. If you are using CloudFront, note that Gzip and Brotli are supported natively. You don't have to do the compression yourself, you can just enable the compression in your cache policy. |
yes i am using CloudFront , so its enough to set this Compress Objects Automatically to Yes inside my cloudfront Behavior right? i will remove it then :) thanks for the info , but what should i do to fix the redirect ? thanks |
Please try disabling your custom gzip/brotli code along with any related Lambda@Edge script and enable the Compress Objects Automatically setting and see if that fixes it. It's my hunch that the redirect issue was related to the Lambda@Edge you were using to load the .gz and .br files. (Although at this point I don't have enough information to be sure) |
Thanks :) i only use 2 Lambda@Edge , one for cache and one for loading index.html. thanks for your time |
Origin Request :
Origin Response
|
Can you please check if an object has been uploaded to Your remaining Lamda's are also unnecessary, assuming that you're using S3 Static Website Hosting. S3 Static Website Hosting automatically adds trailing slashes and index documents:
However, if you exclude the trailing slash from the preceding URL, Amazon S3 first looks for an object
Did you follow a tutorial that recommended them? I suggest you follow our own documentation which includes everything you need in order to get a Gatsby site deployed to S3+CloudFront with caching and serverside redirects. I'm happy to keep troubleshooting with you, but the easiest/fastest way to get your site working might be to start again and follow our recipe. |
Thanks a lot ! i will check the documentation u mentioned and update you with the result tomorrow ^_^ thanks again for your time , good night |
Good find. Prefixes are the cause of quite a bit of confusion, as seen in #24. Could you try including Gatsby's |
now this will definitely upload my build in the root of the s3 bucket out side of the main de folder and routing with /de prefix will not work , but i will check at least the redirect thingy , testing now , i will update you here soon :) thanks |
@JoshuaWalsh ok now i see
with one de , which is good i guess . but in the root of my s3 bucket , i can see |
What are you using to create the redirects? Are you calling At this point I am confident that there is a bug in What's less obvious to me is which behaviour is correct. As I expressed on #24 I think Gatsby's |
make sense , i am using
inside a loop, so no i am not using the plugin you mentioned. |
It seems from here and here that maybe Gatsby itself is prefixing the paths. I'll try to raise this with the Gatsby Core team and see what they advise. This is unlikely to be a quick fix sorry, but I want to make sure we do this right. In the meantime, your best option might be to create a private fork and remove these lines. |
@JoshuaWalsh Thank you so much for your effort , please let me know once you hear from Gatsby or if you could fix this somehow in s3 plugin. Thanks |
Creating a fork duplicates the project into a repository that you own. You can change that freely. If we make updates to our version you can pull those into your repository, and if you make changes that you think we'd like you can submit a Pull Request to us. In your website's package.json you have a line that looks something like this: "gatsby-plugin-s3": "^0.3.8" If your fork is hosted on GitHub, you can alter this to point to your fork by doing something like: "gatsby-plugin-s3": "ahmadkhalaf1/gatsby-plugin-s3" You can find more details here:
Best of luck :) |
sorry for headache , i tried many ways to install the fork to my Gatsby , every time i get this error
|
In your forked |
but this should work locally only? |
Good question, it was late at night when I gave my last reply and I didn't think it through properly. 3 options:
cd ./node_modules/gatsby-plugin-s3
npm ci
npm run-script build (That last one might or might not work, I've had issues before with npm in nested projects) |
so i used first option and i published the fork to NPM { |
What command are you using to do the deployment? Is it possible your deploy command is still using gatsby-plugin-s3 and not ahmad-gatsby-plugin-s3? |
yes !!! you are right , i forgot to change it sorry . so now things looks much much better and i am sure we are about to fix this , so now after i deploy this is how redirect looks like now . lets say i have redirect from now in my s3 i have 1 main de/ folder which is great 1- 2- an object
|
9/10 times when redirects aren't working it's because CloudFront is configured with an "S3 Origin" instead of using the S3 Static Website Hosting endpoint. Please check your CloudFront Origin settings and verify that it is set to "Custom Origin" with a URL that looks like this: http://stage-mydomain.s3-website-eu-west-1.amazonaws.com/ |
i am trying to find out how to change it to Custom Origin , because when i click edit , i see that i have 3 values will keep you updated |
I think you need to delete the origin and add a new one. |
Check out the "Make a CloudFront Distribution" sectin of this guide. They added the origin while creating the distribution, but you can do the same thing when adding an origin to an existing distribution. Basically you just need to put the S3 Static Website Hosting endpoint in the Origin Domain Name field. |
it working !!!!! i removed my lambda edges for Cache and add index.html as you once told me here it was redirected in 2 stages i want to thank you very much for your time and effort , i would like to tip you or buy you a beer :) please let me know how can i do that. also would like to know what is the next step to fix this bug so i can switch back to your version and removed my Temp NPM . Thanks a lot |
302 redirects in S3 Static Website Hosting are usually to add a trailing slash. If you add a trailing slash to your redirect's Thanks for the offer to buy me a beer. We don't have any mechanism set up for tipping, and I'm just happy that it's working for you. Fixing the bug permanently should be fairly straightforward, but first I want guidance from the Gatsby Core team on how they think redirects should be handled. Unfortunately they recently restructured their community, and now it's harder to get in touch with them. I might try resubmitting my question as a bug instead of a discussion to see if that gets better visibility. At the moment I'm thinking the best solution would be for us to subtract |
@JoshuaWalsh has there been any progress on this issue? |
Hello, Any updates on this issue? Was this fixed? current version of gatsby-plugin-s3 is 0.4.1, which was published 2 months ago. Does that resolve this error? |
Hello :)
I am trying to apply 301 redirect with my Gatsby and S3 + Cloudfront , and so far i have no success ,
i have about 204 redirect url , i will list below my configuration .
The text was updated successfully, but these errors were encountered: