<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def redirect(to, *args, **kwargs):
 """ Similar to the Django ``redirect`` shortcut but with altered functionality. If an optional ``params`` argument is provided, the dictionary items will be injected as query parameters on the redirection URL. """

    params = kwargs.pop('params', {})

    try:
        to = reverse(to, args=args, kwargs=kwargs)
    except NoReverseMatch:
        if '/' not in to and '.' not in to:
            to = reverse('cas_login')
        elif not service_allowed(to):
            raise PermissionDenied()

    if params:
        to = add_query_params(to, params)

    logger.debug("Redirecting to %s" % to)
    return HttpResponseRedirect(to)