'Checks to see if a redirect was already installed by certbot.
Checks to see if virtualhost already contains a rewrite rule that is
identical to Certbot\'s redirection rewrite rule.
For graceful transition to new rewrite rules for HTTPS redireciton we
delete certbot\'s old rewrite rules and set the new one instead.
:param vhost: vhost to check
:type vhost: :class:`~certbot_apache.obj.VirtualHost`
:raises errors.PluginEnhancementAlreadyPresent: When the exact
certbot redirection WriteRule exists in virtual host.'

def _verify_no_certbot_redirect(self, vhost):

    rewrite_path = self.parser.find_dir('RewriteRule', None, start=vhost.path)
    rewrite_args_dict = defaultdict(list)
    pat = '(.*directive\\[\\d+\\]).*'
    for match in rewrite_path:
        m = re.match(pat, match)
        if m:
            dir_path = m.group(1)
            rewrite_args_dict[dir_path].append(match)
    if rewrite_args_dict:
        redirect_args = [constants.REWRITE_HTTPS_ARGS, constants.REWRITE_HTTPS_ARGS_WITH_END]
        for (dir_path, args_paths) in rewrite_args_dict.items():
            arg_vals = [self.aug.get(x) for x in args_paths]
            if (arg_vals in constants.OLD_REWRITE_HTTPS_ARGS):
                self.aug.remove(dir_path)
                self._set_https_redirection_rewrite_rule(vhost)
                self.save()
                raise errors.PluginEnhancementAlreadyPresent('Certbot    has    already    enabled    redirection')
            if (arg_vals in redirect_args):
                raise errors.PluginEnhancementAlreadyPresent('Certbot    has    already    enabled    redirection')
