docs: def redirect_legacy_content(request):
      """Redirect from legacy /content/id/version to new /contents/uuid@version.
  
      Handles collection context (book) as well.
      """
      routing_args = request.matchdict
      objid = routing_args['objid']
      objver = routing_args.get('objver')
      filename = routing_args.get('filename')
  
      id, version = _convert_legacy_id(objid, objver)
  
      if not id:
          raise httpexceptions.HTTPNotFound()
  
      # We always use 301 redirects (HTTPMovedPermanently) here
      # because we want search engines to move to the newer links
      # We cache these redirects only briefly because, even when versioned,
      # legacy collection versions don't include the minor version,
      # so the latest archive url could change
      if filename:
          with db_connect() as db_connection:
              with db_connection.cursor() as cursor:
                  args = dict(id=id, version=version, filename=filename)
                  cursor.execute(SQL['get-resourceid-by-filename'], args)
                  try:
                      res = cursor.fetchone()
                      resourceid = res[0]
  
                      raise httpexceptions.HTTPMovedPermanently(
                           request.route_path('resource', hash=resourceid,
                                              ignore=u'/{}'.format(filename)),
                           headers=[("Cache-Control", "max-age=60, public")])
                  except TypeError:  # None returned
                      raise httpexceptions.HTTPNotFound()
  
      ident_hash = join_ident_hash(id, version)
      params = request.params
      if params.get('collection'):  # page in book
          objid, objver = split_legacy_hash(params['collection'])
          book_uuid, book_version = _convert_legacy_id(objid, objver)
          if book_uuid:
              id, ident_hash = \
                  _get_page_in_book(id, version, book_uuid, book_version)
  
      raise httpexceptions.HTTPMovedPermanently(
          request.route_path('content', ident_hash=ident_hash),
          headers=[("Cache-Control", "max-age=60, public")])