Support Log in

22. Redirect Manager

Developer Guide
Prefer video? Watch the Rank Forge tutorials 9 short guides covering every feature Watch

The redirect manager handles 301/302/307/410 HTTP redirects (including regex/wildcard rules), auto-creates redirects when a published post’s slug changes, and tracks 404 errors. Free core feature.

Database Table Schema

sql
CREATE TABLE wp_rankforge_redirects (
    id            bigint(20) unsigned NOT NULL AUTO_INCREMENT,
    source_url    varchar(500) NOT NULL,
    target_url    varchar(500) NOT NULL DEFAULT '',
    redirect_type int(3) NOT NULL DEFAULT 301,
    hits          int(11) NOT NULL DEFAULT 0,
    last_hit      datetime DEFAULT NULL,
    auto_created  tinyint(1) NOT NULL DEFAULT 0,
    created_at    datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (id),
    UNIQUE KEY source_url (source_url(191)),
    KEY redirect_type (redirect_type)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

Programmatic Redirect Management

php
$redirects = RANKFORGE_Redirects::instance();

// Add a 301 permanent redirect
$id = $redirects->add( 'old-page', 'https://example.com/new-page/', 301, false );

// Add a 302 temporary redirect
$id = $redirects->add( 'promo-2023', 'https://example.com/promo-2024/', 302, false );

// Get all redirects as an array of objects
$all = $redirects->get_all();

// Get the 404 log
$log = $redirects->get_404_log();
// Returns: [ 'old-page' => 5, 'missing-post' => 2, ... ]

Custom Redirect Rules

php
// Auto-create redirects from 404 log for high-traffic URLs
$log = RANKFORGE_Redirects::instance()->get_404_log();
foreach ( $log as $url => $hits ) {
    if ( $hits >= 5 ) {
        RANKFORGE_Redirects::instance()->add( $url, home_url( '/' ), 301, false );
    }
}

// Delete all auto-created redirects
global $wpdb;
$wpdb->delete(
    $wpdb->prefix . 'rankforge_redirects',
    [ 'auto_created' => 1 ],
    [ '%d' ]
);

// Query high-traffic redirects
$high_traffic = $wpdb->get_results(
    $wpdb->prepare(
        "SELECT * FROM {$wpdb->prefix}rankforge_redirects WHERE hits > %d ORDER BY hits DESC LIMIT %d",
        100, 20
    )
);

404 Tracking

On every 404 page load, the request path is logged to a transient (rankforge_404_log) with hit counts. The log retains the top 50 URLs for one week.

Forge AI Assistant Online

Hi! I'm the Rank Forge AI assistant. Ask me anything about the plugin — setup, features, troubleshooting, or development.

Just now
Powered by Forge AI · Browse docs