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

Support S3 server-side redirects #14

Open
tomdyson opened this issue Apr 18, 2017 · 3 comments
Open

Support S3 server-side redirects #14

tomdyson opened this issue Apr 18, 2017 · 3 comments

Comments

@tomdyson
Copy link
Contributor

http://docs.aws.amazon.com/AmazonS3/latest/dev/how-to-page-redirect.html

Just an idea :)

@robmoorman
Copy link
Collaborator

This is actually quite interesting @tomdyson thanks! Although you force the user to use S3 (it's an option now). I'll contact the guys from django-bakery, there are some ideas to make adapters (like azure storage, etc.). This will be a great addition to that!

@dprothero
Copy link

Yeah, we rolled our own for use with Wagtail...

def create_s3_redirects(self):
    self.stdout.write('Creating redirects')
    site = Site.objects.filter(is_default_site=True).first()
    redirects = Redirect.objects.all()
    for r in redirects:
        old_path = r.old_path[1:]  # strip leading /
        self.stdout.write(old_path)
        dest_url = r.redirect_link
        if r.redirect_page:
            dest_url = r.redirect_page.specific.relative_url(
                r.site or site
            )
            dest_url = settings.BASE_URL + dest_url
        self.create_s3_redirect(old_path, dest_url)

def create_s3_redirect(self, old_path, dest_url):
    self.s3.meta.client.put_object(Bucket=settings.AWS_STORAGE_BUCKET_NAME,
                                   Key=old_path,
                                   WebsiteRedirectLocation=dest_url)

So if you implement the adapter idea, there'd be a method to create redirects and those backends that couldn't do redirects could just stub it out.

@robmoorman
Copy link
Collaborator

Awesome @dprothero. However support for Redirects is missing now actually in this module. A separate RedirectView with a get_queryset set to all Wagtail redirects (which renders the redirect html templates) would also work for some people.

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

No branches or pull requests

3 participants