Skip to content
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

Patch to set S3 redirects? #129

Closed
mathie opened this issue Jul 13, 2016 · 9 comments
Closed

Patch to set S3 redirects? #129

mathie opened this issue Jul 13, 2016 · 9 comments

Comments

@mathie
Copy link

mathie commented Jul 13, 2016

I've wound up monkey patching Middleman & s3sync to support setting x-amz-website-redirect-location on resources configured with the redirect method in config.rb:https://github.com/wossname/woss.name/blob/master/helpers/s3_redirects.rb. Is that the sort of thing I should be tidying up into a pull request at some point?

@fredjean
Copy link
Owner

Absolutely. I haven't been paying any attention to s3_redirect and merging this into s3_sync makes a lot of sense.

@mathie
Copy link
Author

mathie commented Jul 13, 2016

Awesome. In which case, I'll tidy it up into a pull request. 😄

@umerebryx
Copy link

umerebryx commented Aug 27, 2019

@mathie, @matiasgarciaisaia I was using https://github.com/fredjean/middleman-s3_redirect for setting up redirects on my s3 bucket. Can your PR be used as an alternative for this? If yes, is there any documentation/example I can use to setup my project?

@matiasgarciaisaia
Copy link
Contributor

Hi @umerebryx!

Do you have this gem installed and configured on your project?

Once you add the extension as usual, this PR makes your Middleman's redirects work at an S3 level. I think they were previously generating a small HTML file with a redirect header, but now it just let's S3 now that they should set up a redirection.

So for example you can add redirect "this/page.html", to: "my-aweseome-page.html" to make visitors to yoursite.com/this/page.html get redirected to yoursite.com/my-awesome-page.html.

Not sure if that helped, though.

@umerebryx
Copy link

@matiasgarciaisaia , yes I have middleman-s3_sync configured. I have tried adding redirect method based on your example above but I am getting error NoMethodError: undefined method redirect

activate :s3_sync do |s3_sync|
s3_sync.path_style = true
s3_sync.reduced_redundancy_storage = false
s3_sync.acl = 'public-read'
s3_sync.encryption = false
s3_sync.redirect 'jobs/tech-support-specialist.html', to: '/jobs/test/'

Not sure if I am doing it right. Can you correct my usage of redirect above I am adding this to config.rb. Thanks for your help.

@matiasgarciaisaia
Copy link
Contributor

redirect isn't a method from s3_sync - it's the Middleman's standard redirect method.

So your snippet would be something like:

activate :s3_sync do |s3_sync|
  s3_sync.path_style = true
  s3_sync.reduced_redundancy_storage = false
  s3_sync.acl = 'public-read'
  s3_sync.encryption = false
end

redirect 'jobs/tech-support-specialist.html', to: '/jobs/test/'
redirect 'yes-we-are-specialists.html', to: '/jobs/test/'

(assuming the rest of the s3_sync properties you're setting are correct - I haven't checked.

@umerebryx
Copy link

Thanks @matiasgarciaisaia , I got the redirects to work locally. But when I use s3_sync to update my s3 bucket these redirects are not synced. I am also calling sitemap.ensure_resource_list_updated! right after redirects:

redirect 'jobs/account-manager/index.html', to: '/jobs/umer/index.html'
sitemap.ensure_resource_list_updated!

Is it possible I have to add above block at a certain place in my config.rb?

@matiasgarciaisaia
Copy link
Contributor

My only suggestion is to run the s3_sync in verbose mode and share the output to check what could be going on.

@pwim
Copy link

pwim commented Oct 9, 2019

@umerebryx I also ran in to this issue, but realized it is because the most recent release doesn't contain the PR that adds support. I've created #158 to ask for a new version to be released. In the meantime, you can use it if you specify to use the github version:

gem 'middleman-s3_sync', github: "fredjean/middleman-s3_sync"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants