🖥️ CMS & Plugin Implementation
Complete guide to implementing 301 redirects in popular Content Management Systems and E-commerce platforms
📚 Table of Contents
🎯 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
- Install Plugin: WordPress Admin → Plugins → Add New → Search "Redirection"
- Activate and Configure: Choose monitoring settings and log preferences
- Add Redirects: Tools → Redirection → Add New
- Configure Source URL: Enter the old URL (relative path)
- Set Target URL: Enter destination URL (can be absolute or relative)
- Choose Type: Select 301 - Moved Permanently
- Save and Test: Save redirect and test functionality
🎯 Rank Math Redirect Setup
- Enable Module: Rank Math → Dashboard → Modules → Redirections
- Access Manager: Rank Math → Redirections
- Add New Redirect: Click "Add New" button
- Source Configuration: Enter source URL and select match type
- Destination Setup: Enter target URL
- Advanced Options: Configure redirect type and additional settings
- 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.
- Enable Redirect Plugin: Extensions → Plugins → System - Redirect
- Access Component: Components → Redirect
- Review 404 Errors: Check captured broken URLs
- Create Redirects: Add destination URLs for captured 404s
- 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();
- Install Module: Use Composer or manual installation
- Configure Settings: Admin → Configuration → Search and metadata → URL redirects
- Add Redirects: Manually or import from CSV
- Global Redirects: Configure domain-level redirects
- 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.
- Access Redirects: Online Store → Navigation → URL Redirects
- Create Redirect: Click "Create URL redirect"
- Enter URLs: Add source and destination URLs
- Bulk Import: Use CSV import for multiple redirects
- 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
- Pre-Migration Planning: Document all current URLs and their purposes
- Content Mapping: Map old content to new structure before migration
- Staged Implementation: Implement redirects in phases to monitor impact
- Testing Phase: Thoroughly test all redirects in staging environment
- Monitoring Setup: Configure monitoring before going live
- Post-Migration Review: Analyze performance and fix issues promptly