rochacbruno-archive / quokka_ng

:hamster: WIP - QuokkaCMS New Generation - Refactor from scratch using TinyDB
Other
73 stars 19 forks source link

redirect system for old site migrations #74

Open rochacbruno opened 7 years ago

rochacbruno commented 7 years ago

Create a system to redirect old urls (see django-redirects)

Pal0r commented 7 years ago

@rochacbruno I can add this for your app. Are you wanting to maintain the old links for SEO purposes, redirecting them(301) to new views in app? That's fairly easy with django-redirects, but we'll need a list of old/new links for a data migration.

Or I can create a middleware class for 404s. Maybe do both. Your call!

Something like:

class Redirect404Middleware(object):
     def process_response(self, request, response):
         if response == Http404:
             return HttpResponsePermanentRedirect('/')

         return response
rochacbruno commented 7 years ago

@Pal0r

The idea is.

Following the example of https://github.com/rochacbruno/quokka_ng/blob/master/quokka/core/auth.py a new core extension should be created quokka/core/redirects.py

That extension should define a configure(app) function which will be included in quokka/project_template/quokka.yml:CORE_EXTENSIONS

When loaded that new extension should provide a new tab in /admin panel, A form to register redirects in app.db.redirects collections.

old_url new_url http_code
/this-url-not-exists-anymore.html /hello-new-url 301

So on the Redirect middleware when a 404 is raised, that database app.db.redirects.find_one({'old_url': request.url}) can be queried and if a redirect exists it raises it.