Enjoying these plugins? ☕ Buy me a coffee to support ongoing development.

Custom Redirect Manager

A simple and powerful WordPress plugin for managing 301 redirects with CSV import/export functionality. Perfect for site migrations, URL restructuring, and SEO management.

Single File v1.0.0 Updated 1 month ago

YT Custom Redirect Manager

A simple and powerful WordPress plugin for managing 301 redirects with CSV import/export functionality. Perfect for site migrations, URL restructuring, and SEO management.

Features

  • Simple Admin UI: Easy-to-use interface for managing redirects
  • 301 Redirects: Proper permanent redirects for SEO
  • CSV Import: Bulk import redirects from CSV files
  • CSV Export: Export all redirects for backup or migration
  • Fast Execution: Uses template_redirect hook for early processing
  • URL Normalization: Handles both relative and absolute URLs
  • Duplicate Detection: Prevents duplicate source URLs
  • Search Functionality: Quick search through your redirects
  • Click to Copy: Click any URL to copy it to clipboard
  • Responsive Design: Mobile-friendly admin interface
  • WPCS Compliant: Follows WordPress coding standards

Installation

  1. Upload the yt-custom-redirect-manager folder to the /wp-content/plugins/ directory
  2. Activate the plugin through the 'Plugins' menu in WordPress
  3. Go to Tools → Redirects to manage your redirects
  4. Add redirects manually or import from CSV

Usage

Adding Redirects Manually

  1. Navigate to Tools → Redirects
  2. Fill in the "Add New Redirect" form:
    • Source URL: The old URL to redirect from (e.g., /old-page)
    • Destination URL: The new URL to redirect to (e.g., /new-page)
  3. Click "Add Redirect"

URL Formats Supported

Relative URLs (recommended):

Source: /old-page
Destination: /new-page

Absolute URLs:

Source: https://yoursite.com/old-page
Destination: https://yoursite.com/new-page

External URLs:

Source: /old-page
Destination: https://external-site.com/page

Mixed formats:

Source: /old-page
Destination: https://yoursite.com/new-page

CSV Import

  1. Prepare your CSV file with two columns: source and destination
  2. Example CSV format:
    source,destination
    /old-page-1,/new-page-1
    /old-page-2,/new-page-2
    /old-blog,/blog
  3. Go to Tools → Redirects
  4. Click "Choose File" under Import/Export section
  5. Select your CSV file
  6. Click "Import CSV"

CSV Export

  1. Go to Tools → Redirects
  2. Click "Export CSV" button
  3. Save the downloaded file (redirects-YYYY-MM-DD.csv)
  4. Use this file for backup or migration to another site

How It Works

Redirect Processing

  1. User visits a URL (e.g., /old-page)
  2. Plugin checks if URL matches any source URLs
  3. If match found, redirects to destination URL (301 permanent)
  4. If no match, WordPress continues normal page loading

Execution Flow

template_redirect hook (priority 1)
  ↓
Get current URL
  ↓
Normalize URL format
  ↓
Loop through redirects
  ↓
Match found? → wp_safe_redirect() with 301
  ↓
No match? → Continue to WordPress

URL Normalization

The plugin normalizes URLs for consistent matching:

Input variations:

  • old-page/old-page
  • /old-page//old-page
  • https://site.com/old-page/old-page

Normalized output:

  • Leading slash added if missing
  • Trailing slashes removed (except root /)
  • Full URLs converted to paths for matching

Admin Interface

Dashboard Sections

  1. Statistics

    • Total number of active redirects
  2. Import/Export

    • CSV file upload for bulk import
    • One-click export of all redirects
  3. Add New Redirect

    • Source URL field with validation
    • Destination URL field with validation
    • Auto-formatting of URLs
  4. Current Redirects

    • Table showing all active redirects
    • Source and destination URLs
    • 301 redirect type badge
    • Delete button for each redirect
    • Search functionality
    • Click to copy URLs

File Structure

yt-custom-redirect-manager/
├── class-yt-custom-redirect-manager.php    # Main plugin file (~600 lines)
├── assets/
│   ├── css/
│   │   └── yt-crm-admin.css                # Admin UI styles
│   └── js/
│       └── yt-crm-admin.js                 # Admin interactions
└── README.md                                # This file

Prefix Convention

All functions, classes, and elements use the yt_crm prefix:

  • Class: YT_Custom_Redirect_Manager
  • Constants: YT_CUSTOM_REDIRECT_MANAGER_*
  • Functions: yt_crm_*
  • CSS Classes: .yt-crm-*
  • JavaScript Object: ytCrmAdmin
  • Options: yt_custom_redirect_manager_redirects
  • Text Domain: yt-custom-redirect-manager

Database Storage

Redirects are stored as a single option:

  • Option name: yt_custom_redirect_manager_redirects
  • Format: Array of redirect objects
  • Structure:
    array(
      array(
          'source' => '/old-page',
          'destination' => '/new-page'
      ),
      // ... more redirects
    )

Security Features

  • Capability Checks: All admin actions require manage_options
  • Nonce Verification: CSRF protection on all forms
  • Input Sanitization: All inputs sanitized before storage
  • Output Escaping: All output properly escaped
  • File Upload Validation: CSV files validated before processing
  • Safe Redirects: Uses wp_safe_redirect() for security

Performance

  • Early Execution: Runs on template_redirect (priority 1)
  • Fast Matching: Simple array loop with normalized URLs
  • No Database Queries: Redirects loaded once from options
  • Cached in Object: Stored in class property for efficiency
  • Minimal Overhead: Only processes on front-end, not admin

CSV Format

Import Format

source,destination
/old-url-1,/new-url-1
/old-url-2,/new-url-2
/about-old,/about

Export Format

The plugin exports in the same format:

  • Header row: source,destination
  • Each redirect as a row
  • Properly escaped CSV format
  • UTF-8 encoding

CSV Import Rules

  1. Header row: First row can be header (will be skipped if detected)
  2. Two columns: Must have source and destination
  3. Empty rows: Skipped automatically
  4. Duplicates: Source URLs that already exist are skipped
  5. Validation: Empty source or destination are skipped

Use Cases

Site Migration

Moving from old domain to new domain:

source,destination
/,https://newdomain.com/
/about,https://newdomain.com/about
/contact,https://newdomain.com/contact

URL Restructuring

Changing URL structure:

source,destination
/blog/old-post,/articles/old-post
/products/item-1,/shop/item-1
/services/consulting,/consulting

SEO Consolidation

Combining duplicate content:

source,destination
/old-category/post,/new-category/post
/archive/2020/post,/blog/post
/tag/old-tag,/category/new-category

Handling Deleted Content

Redirecting removed pages:

source,destination
/discontinued-product,/products
/old-service,/services
/expired-offer,/

Troubleshooting

Redirects not working?

  1. Check plugin activation: Ensure plugin is activated
  2. Clear cache: Clear any caching plugins or CDN cache
  3. Check URL format: Verify source URL matches exactly
  4. Test in incognito: Browser may cache redirects
  5. Check for conflicts: Disable other redirect plugins

CSV import failing?

  1. Check file format: Must be valid CSV with comma delimiter
  2. Check encoding: Should be UTF-8
  3. Verify structure: Two columns (source, destination)
  4. Check for errors: Look at WordPress admin notices
  5. File size: Very large files may timeout (split into smaller files)

Redirect loops?

If you create circular redirects:

/page-a → /page-b
/page-b → /page-a

This will cause infinite redirects. The plugin doesn't prevent this, so be careful!

Source and destination same?

The JavaScript validation prevents this, but if you import via CSV, the plugin will create the redirect. This is essentially a no-op.

Best Practices

  1. Test redirects: Always test after adding redirects
  2. Use relative URLs: Easier to migrate between environments
  3. Export regularly: Keep backups of your redirect rules
  4. Document changes: Keep notes on why redirects were created
  5. Clean up old redirects: Remove redirects for pages that no longer need them
  6. Use 301 for permanent: Plugin uses 301 (permanent) - appropriate for most cases
  7. Avoid redirect chains: Redirect directly to final destination

Limitations

Current Version

  • 301 only: Only permanent redirects (not 302 temporary)
  • Exact match: No wildcard or regex matching
  • No conditions: Can't redirect based on user role, device, etc.
  • No redirect history: Doesn't track redirect hits or statistics
  • Single destination: Each source has one destination

Not Included

  • Analytics: No tracking of redirect usage
  • Bulk edit: No bulk delete or edit functionality
  • Redirect chains: No detection of redirect chains
  • URL parameters: Query strings not preserved
  • Complex patterns: No regex or wildcard support

Uninstallation

When the plugin is deleted via WordPress admin:

  1. All redirects are removed from database
  2. Plugin option is deleted
  3. WordPress cache is flushed
  4. No traces left behind

Requirements

  • WordPress 5.8 or higher
  • PHP 7.4 or higher
  • manage_options capability for admin access

Complexity

  • Main PHP File: ~600 lines (with comments)
  • CSS File: ~165 lines
  • JS File: ~215 lines
  • Total: ~980 lines across all files

FAQ

Can I redirect to external sites?

Yes! Just use the full URL in the destination field:

Source: /old-page
Destination: https://external-site.com/page

Does it preserve query strings?

No, query strings are not automatically preserved. You need to include them in your redirect rules.

Can I redirect the homepage?

Yes, use / as the source URL:

Source: /
Destination: /new-home

How many redirects can I have?

There's no hard limit, but performance may degrade with thousands of redirects. For large-scale redirects, consider server-level solutions.

Does it work with custom post types?

Yes! The plugin intercepts all URLs before WordPress routing, so it works with posts, pages, custom post types, and even non-existent URLs.

Can I import from other redirect plugins?

If you can export to CSV format from another plugin, you can import here. Just ensure the CSV has source and destination columns.

What about regex or wildcards?

Not supported in this lite version. Each redirect is an exact match.

Changelog

1.0.0

  • Initial release
  • 301 redirect functionality
  • Admin UI for managing redirects
  • CSV import functionality
  • CSV export functionality
  • URL normalization
  • Duplicate detection
  • Search functionality
  • Click to copy URLs
  • Mobile-responsive design

License

GPL v2 or later

Author

Krasen Slavov

Support

For issues and feature requests, please visit the GitHub repository.

Future Enhancements

Potential features for future versions:

  • Redirect statistics and analytics
  • 302 temporary redirects
  • Wildcard matching
  • Regex pattern support
  • Bulk delete functionality
  • Redirect chains detection
  • Import from other plugins
  • Conditional redirects (user role, device, etc.)
  • Query string preservation
  • Redirect testing tool