function WPSR_redirect()
{
    global $wpdb, $table_prefix, $util;
    if ($util->get_option_value('plugin_status') == '1') {
        $table_name = $table_prefix . 'WP_SEO_Redirection';
        $permalink = urldecode($util->get_current_relative_url());
        if (substr($permalink, 0, 1) == ":") {
            $first_slash = stripos($permalink, "/");
            $permalink = substr($permalink, $first_slash, strlen($permalink) - $first_slash);
        }
        $post_cache_result = "";
        $SR_redirect_cache = new clogica_SR_redirect_cache();
        if (is_singular()) {
            $post_cache_result = $SR_redirect_cache->redirect_cached(get_the_ID());
        }
        if ($post_cache_result == 'not_redirected') {
            return 0;
        }
        $permalink_alternative = "";
        if (substr($permalink, -1) == '/') {
            $permalink_alternative = substr($permalink, 0, intval(strlen($permalink) - 1));
        } else {
            $permalink_alternative = $permalink . '/';
        }
        $permalink_options = "(redirect_from='{$permalink}' or redirect_from='{$permalink_alternative}' )";
        $permalink_regex_options = "('{$permalink}' regexp regex or '{$permalink_alternative}'  regexp regex )";
        if ($util->get_option_value('redirect_control_panel') != '1' || $util->get_option_value('redirect_control_panel') == '1' && !preg_match('/^' . str_replace('/', '\\/', get_admin_url()) . '/i', $permalink) && !preg_match('/^' . str_replace('/', '\\/', site_url()) . '\\/wp-login.php/i', $permalink)) {
            $theurl = $wpdb->get_row(" select * from {$table_name} where enabled=1 and regex='' and {$permalink_options}  ");
            if ($wpdb->num_rows > 0 && $theurl->redirect_to != '') {
                WPSR_make_redirect($theurl->redirect_to, $theurl->redirect_type, $permalink, $theurl);
            }
            $theurl = $wpdb->get_row(" select * from {$table_name} where enabled=1 and regex<>'' and {$permalink_regex_options} order by LENGTH(regex) desc ");
            if ($wpdb->num_rows > 0 && $theurl->redirect_to != '') {
                WPSR_make_redirect($theurl->redirect_to, $theurl->redirect_type, $permalink, $theurl);
            }
            if (is_404()) {
                if ($util->get_option_value('p404_discovery_status') == '1') {
                    WPSR_log_404_redirection($permalink);
                }
                $options = $util->get_my_options();
                if ($options['p404_status'] == '1') {
                    WPSR_make_redirect($options['p404_redirect_to'], '301', $permalink);
                }
            }
        }
        if (is_singular() && $post_cache_result == 'not_found') {
            $SR_redirect_cache->add_redirect(get_the_ID(), 0, '', 0);
        }
    }
}