Closed mathie closed 7 years ago
Absolutely. I haven't been paying any attention to s3_redirect and merging this into s3_sync makes a lot of sense.
Awesome. In which case, I'll tidy it up into a pull request. 😄
@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?
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 redirect
s 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.
@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.
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.
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?
My only suggestion is to run the s3_sync
in verbose mode and share the output to check what could be going on.
@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"
I've wound up monkey patching Middleman & s3sync to support setting
x-amz-website-redirect-location
on resources configured with theredirect
method inconfig.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?