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.
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_redirecthook 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
- Upload the
yt-custom-redirect-managerfolder to the/wp-content/plugins/directory - Activate the plugin through the 'Plugins' menu in WordPress
- Go to Tools → Redirects to manage your redirects
- Add redirects manually or import from CSV
Usage
Adding Redirects Manually
- Navigate to Tools → Redirects
- 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)
- Source URL: The old URL to redirect from (e.g.,
- 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
- Prepare your CSV file with two columns:
sourceanddestination - Example CSV format:
source,destination /old-page-1,/new-page-1 /old-page-2,/new-page-2 /old-blog,/blog - Go to Tools → Redirects
- Click "Choose File" under Import/Export section
- Select your CSV file
- Click "Import CSV"
CSV Export
- Go to Tools → Redirects
- Click "Export CSV" button
- Save the downloaded file (
redirects-YYYY-MM-DD.csv) - Use this file for backup or migration to another site
How It Works
Redirect Processing
- User visits a URL (e.g.,
/old-page) - Plugin checks if URL matches any source URLs
- If match found, redirects to destination URL (301 permanent)
- 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-pagehttps://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
-
Statistics
- Total number of active redirects
-
Import/Export
- CSV file upload for bulk import
- One-click export of all redirects
-
Add New Redirect
- Source URL field with validation
- Destination URL field with validation
- Auto-formatting of URLs
-
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
- Header row: First row can be header (will be skipped if detected)
- Two columns: Must have source and destination
- Empty rows: Skipped automatically
- Duplicates: Source URLs that already exist are skipped
- 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?
- Check plugin activation: Ensure plugin is activated
- Clear cache: Clear any caching plugins or CDN cache
- Check URL format: Verify source URL matches exactly
- Test in incognito: Browser may cache redirects
- Check for conflicts: Disable other redirect plugins
CSV import failing?
- Check file format: Must be valid CSV with comma delimiter
- Check encoding: Should be UTF-8
- Verify structure: Two columns (source, destination)
- Check for errors: Look at WordPress admin notices
- 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
- Test redirects: Always test after adding redirects
- Use relative URLs: Easier to migrate between environments
- Export regularly: Keep backups of your redirect rules
- Document changes: Keep notes on why redirects were created
- Clean up old redirects: Remove redirects for pages that no longer need them
- Use 301 for permanent: Plugin uses 301 (permanent) - appropriate for most cases
- 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:
- All redirects are removed from database
- Plugin option is deleted
- WordPress cache is flushed
- No traces left behind
Requirements
- WordPress 5.8 or higher
- PHP 7.4 or higher
manage_optionscapability 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
- Website: https://krasenslavov.com
- GitHub: https://github.com/krasenslavov
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