🎯 WordPress Redirect Implementation

⚙️ Native WordPress Methods

functions.php Implementation
<?php
// Method 1: Using wp_redirect() in functions.php
function custom_page_redirects() {
    if (is_page('old-page-slug')) {
        wp_redirect(home_url('/new-page/'), 301);
        exit();
    }
    
    // Redirect old category to new category
    if (is_category('old-category-slug')) {
        wp_redirect(home_url('/category/new-category/'), 301);
        exit();
    }
}
add_action('template_redirect', 'custom_page_redirects');

// Method 2: Redirect based on URL structure
function legacy_url_redirects() {
    $request_uri = $_SERVER['REQUEST_URI'];
    
    // Old blog structure: /2023/01/post-name/ → /blog/post-name/
    if (preg_match('/^\/(\d{4})\/(\d{2})\/(.+)\/$/', $request_uri, $matches)) {
        $post_slug = $matches[3];
        wp_redirect(home_url('/blog/' . $post_slug . '/'), 301);
        exit();
    }
}
add_action('init', 'legacy_url_redirects');
?>

💡 WordPress Hooks for Redirects

template_redirect: Best for page-specific redirects

init: Good for URL pattern matching

wp: Useful for 404 redirects

🔧 WordPress Hooks for Advanced Redirects

Advanced WordPress Redirects
<?php
// Hook into WordPress query to handle redirects
function handle_custom_redirects() {
    global $wp_query;
    
    // Redirect 404 pages that match certain patterns
    if (is_404()) {
        $request_uri = $_SERVER['REQUEST_URI'];
        
        // Check if it's an old product URL
        if (preg_match('/^\/products\/old-(.+)\/$/', $request_uri, $matches)) {
            $product_slug = $matches[1];
            wp_redirect(home_url('/shop/' . $product_slug . '/'), 301);
            exit();
        }
    }
}
add_action('wp', 'handle_custom_redirects');

// Redirect based on post type
function redirect_old_post_types() {
    if (is_singular('old_post_type')) {
        global $post;
        $new_url = home_url('/new-section/' . $post->post_name . '/');
        wp_redirect($new_url, 301);
        exit();
    }
}
add_action('template_redirect', 'redirect_old_post_types');
?>

🔌 WordPress Plugins Detailed Comparison

Plugin Free/Paid Features Performance Best For
Redirection Free ✅ Comprehensive features
✅ 404 monitoring
✅ Import/Export
✅ Logs
🟡 Medium impact General use, detailed tracking
Rank Math SEO Free + Pro ✅ SEO integration
✅ Smart redirects
✅ Bulk redirects
✅ Pattern matching
🟢 Light impact SEO-focused sites, all-in-one solution
Yoast SEO Premium Paid ✅ SEO integration
✅ Automatic redirects
✅ Redirect manager
🟢 Light impact Yoast users, automatic handling
Safe Redirect Manager Free ✅ Simple interface
✅ Regex support
✅ Minimal features
🟢 Very light Simple setups, performance-focused
Simple 301 Redirects Free ✅ Basic redirects
❌ No patterns
❌ Manual entry only
🟢 Very light Basic needs, few redirects

🏆 Best Overall: Redirection

  • Comprehensive feature set
  • Excellent 404 error monitoring
  • Detailed logging and statistics
  • Import/export capabilities
  • Regular expression support

⚡ Best Performance: Safe Redirect Manager

  • Minimal resource usage
  • Clean, simple interface
  • Regex pattern support
  • No unnecessary features
  • Developer-friendly

🔍 Best for SEO: Rank Math

  • Integrated SEO features
  • Smart redirect suggestions
  • Bulk redirect operations
  • Pattern-based redirects
  • Comprehensive SEO suite

🔧 Redirection Plugin Setup Guide

  1. Install Plugin: WordPress Admin → Plugins → Add New → Search "Redirection"
  2. Activate and Configure: Choose monitoring settings and log preferences
  3. Add Redirects: Tools → Redirection → Add New
  4. Configure Source URL: Enter the old URL (relative path)
  5. Set Target URL: Enter destination URL (can be absolute or relative)
  6. Choose Type: Select 301 - Moved Permanently
  7. Save and Test: Save redirect and test functionality

🎯 Rank Math Redirect Setup

  1. Enable Module: Rank Math → Dashboard → Modules → Redirections
  2. Access Manager: Rank Math → Redirections
  3. Add New Redirect: Click "Add New" button
  4. Source Configuration: Enter source URL and select match type
  5. Destination Setup: Enter target URL
  6. Advanced Options: Configure redirect type and additional settings
  7. Bulk Operations: Use bulk features for multiple redirects

🌐 Other CMS Platforms

🔧 Joomla Redirects

🏗️ Built-in System

Joomla has a native redirect component that automatically captures 404 errors and allows easy redirect creation.

  1. Enable Redirect Plugin: Extensions → Plugins → System - Redirect
  2. Access Component: Components → Redirect
  3. Review 404 Errors: Check captured broken URLs
  4. Create Redirects: Add destination URLs for captured 404s
  5. Manage Status: Enable/disable redirects as needed
Joomla .htaccess Examples
# Joomla .htaccess redirect examples
# Add these to your Joomla .htaccess file

# Redirect old articles to new structure
RewriteRule ^old-section/([^/]+)/?$ /new-section/$1 [R=301,L]

# Redirect old component URLs
RewriteRule ^component/content/article/([0-9]+)/?$ /articles/$1 [R=301,L]

🛍️ Drupal Redirects

Drupal 8/9/10 Implementation
# Drupal 8/9/10 redirect module usage

# 1. Install Redirect module
composer require drupal/redirect

# 2. Enable module
drush en redirect

# 3. Create redirects programmatically
$redirect = Redirect::create([
  'redirect_source' => 'old-path',
  'redirect_redirect' => 'internal:/new-path',
  'language' => 'und',
  'status_code' => 301,
]);
$redirect->save();
  1. Install Module: Use Composer or manual installation
  2. Configure Settings: Admin → Configuration → Search and metadata → URL redirects
  3. Add Redirects: Manually or import from CSV
  4. Global Redirects: Configure domain-level redirects
  5. Path Auto Integration: Automatic redirects when changing URLs

🔧 Bitrix Redirects

Bitrix Configuration
# Bitrix .htaccess redirect configuration
RewriteEngine On

# Bitrix-specific redirects
RewriteCond %{HTTP_HOST} ^old-domain\.com$ [NC]
RewriteRule ^(.*)$ https://new-domain.com/$1 [R=301,L]

# Bitrix component redirects
RewriteRule ^old-catalog/(.*)$ /catalog/$1 [R=301,L]

🛒 E-commerce Platform Redirects

🎯 Shopify Redirects

🏗️ Built-in Feature

Shopify has a native URL redirect feature in the admin panel with support for bulk imports.

  1. Access Redirects: Online Store → Navigation → URL Redirects
  2. Create Redirect: Click "Create URL redirect"
  3. Enter URLs: Add source and destination URLs
  4. Bulk Import: Use CSV import for multiple redirects
  5. Test Redirects: Verify functionality before going live
Shopify CSV Import Format
Redirect from,Redirect to
/old-product,/collections/new-products/products/new-product
/old-collection,/collections/new-collection
/old-page,/pages/new-page

🛍️ WooCommerce Redirects

WooCommerce Custom Redirects
<?php
// WooCommerce-specific redirects in functions.php

// Redirect old product URLs
function woocommerce_custom_redirects() {
    if (is_product()) {
        global $post;
        
        // Redirect old product structure
        if (strpos($_SERVER['REQUEST_URI'], '/old-products/') !== false) {
            $new_url = str_replace('/old-products/', '/shop/', $_SERVER['REQUEST_URI']);
            wp_redirect(home_url($new_url), 301);
            exit();
        }
    }
}
add_action('template_redirect', 'woocommerce_custom_redirects');

// Redirect old shop categories
function redirect_old_product_categories() {
    if (is_product_category()) {
        $category = get_queried_object();
        
        if ($category->slug === 'old-category-slug') {
            wp_redirect(home_url('/product-category/new-category-slug/'), 301);
            exit();
        }
    }
}
add_action('template_redirect', 'redirect_old_product_categories');
?>

🛒 Magento Redirects

Magento 2 Redirect Configuration
# Magento 2 redirect configuration

# 1. Admin panel redirects
Admin Panel → Marketing → SEO & Search → URL Rewrites

# 2. Programmatic redirects in app/code
<?php
namespace Vendor\Module\Controller\Index;

use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\Controller\Result\RedirectFactory;

class Redirect extends Action
{
    protected $redirectFactory;
    
    public function __construct(Context $context, RedirectFactory $redirectFactory)
    {
        $this->redirectFactory = $redirectFactory;
        parent::__construct($context);
    }
    
    public function execute()
    {
        $redirect = $this->redirectFactory->create();
        return $redirect->setUrl('/new-url')->setHttpResponseCode(301);
    }
}
?>

🔧 OpenCart Redirects

OpenCart .htaccess Redirects
# OpenCart .htaccess redirects
RewriteEngine On

# Old product URLs to new structure
RewriteRule ^product/([0-9]+)/?$ /index.php?route=product/product&product_id=$1 [R=301,L]

# Old category URLs
RewriteRule ^old-category/?$ /new-category [R=301,L]

✅ CMS-Specific Best Practices

🎯 WordPress Best Practices

  • Use plugins for complex redirect management
  • Implement redirects in functions.php for simple cases
  • Always use template_redirect or init hooks
  • Test redirects with different user roles
  • Monitor redirect performance impact
  • Keep redirect databases clean and updated
  • Use relative URLs when possible for flexibility

🛡️ Security Considerations

⚠️ Security Risks

  • Open Redirects: Never redirect to external URLs without validation
  • Input Validation: Sanitize all URL inputs in custom redirect code
  • Access Control: Limit redirect management to administrators
  • Log Monitoring: Monitor redirect logs for suspicious activity

⚡ Performance Optimization

🚀 Speed Optimization

  • Use server-level redirects when possible
  • Minimize plugin overhead
  • Implement caching for redirect lookups
  • Avoid database queries in redirect logic

📊 Database Efficiency

  • Index redirect tables properly
  • Clean up old, unused redirects
  • Use efficient query patterns
  • Consider redirect limits

🔄 Migration Strategies

  1. Pre-Migration Planning: Document all current URLs and their purposes
  2. Content Mapping: Map old content to new structure before migration
  3. Staged Implementation: Implement redirects in phases to monitor impact
  4. Testing Phase: Thoroughly test all redirects in staging environment
  5. Monitoring Setup: Configure monitoring before going live
  6. Post-Migration Review: Analyze performance and fix issues promptly