Log WP Redirects is a powerful WordPress plugin that captures and logs all redirects made through WordPress's built-in wp_redirect()
function, providing valuable insights for debugging and monitoring.
- 📊 Log all redirects with detailed information
- 🔢 Track HTTP status codes (301, 302, 307, etc.)
- 🔗 Record referrer URLs and request URIs
- 🖥️ Capture user agent information
- 👤 Track user IDs for authenticated users
- 🌐 IP address logging (configurable)
- 🍪 Cookie tracking (names only, not values)
- 🔍 Full backtrace to identify redirect sources
- 🌍 Multisite/Network compatible
- ⏱️ Configurable log retention period
Main settings page showing the redirect log interface.
Detailed view of a specific redirect with complete stack trace.
Network admin interface for managing redirects across multiple sites.
- Upload the
log-wp-redirects
folder to your/wp-content/plugins/
directory - Activate the plugin through the 'Plugins' menu in WordPress
- For single sites, access logs via Tools > Log WP Redirects
- For multisite, access network-wide logs via Network Admin > Settings > Log WP Redirects
You can install this plugin via Composer:
composer require beapi/log-wp-redirects
Or add it to your composer.json
file:
"require": {
"beapi/log-wp-redirects": "^1.0"
}
After installing and activating the plugin, it automatically begins capturing all redirects made using WordPress's wp_redirect()
function.
- Go to Tools > Log WP Redirects in your WordPress admin
- View the comprehensive list of all redirects
- Click on a redirect to view detailed information including backtrace
- Go to Network Admin > Settings > Log WP Redirects
- View redirects across all sites or filter by specific site
- Click on a redirect to view detailed information
Customize how long logs are kept before being automatically deleted:
add_filter( 'lwr_expiration_days', function( $days ) {
return 14; // default = 7
});
Filter which redirects should be logged based on status code or other criteria:
// Example: Don't log 302 temporary redirects
add_filter( 'lwr_should_log_redirect', function( $should_log, $status, $location, $redirect_data ) {
if ( 302 === $status ) {
return false;
}
return $should_log;
}, 10, 4 );
Modify the data before it's inserted into the database:
// Example: Remove all cookies information for privacy
add_filter( 'lwr_pre_insert_data', function( $data, $location, $status ) {
// Empty the cookies field
$data['cookies'] = '';
// Or you could also sanitize/modify other fields
// $data['user_agent'] = 'Anonymized';
return $data;
}, 10, 3 );
This plugin logs IP addresses by default. If you need to comply with privacy regulations such as GDPR, you can disable IP logging by defining the following constant in your wp-config.php:
define('LWR_LOG_IP', false);
- WordPress 5.8 or higher
- PHP 7.0 or higher
This project is licensed under the GPLv2 or later license.
- Replaced custom time formatting with WordPress native human_time_diff() function
- Added Composer support for easier installation in modern WordPress projects
- Improved WP-Cron implementation using standard WordPress activation/deactivation hooks
- Switched from single events to properly scheduled daily events for log cleanup
- Added optimized database indexes for better performance, especially for cleanup operations
- Added a composite index (blog_id, date_added) to significantly improve cleanup query performance
- Added support for the
$x_redirect_by
parameter of wp_redirect() function - The source of redirects is now tracked and displayed in the admin interface
- Enhanced database structure to accommodate the new data
- Improved database schema management using WordPress's dbDelta() function
- Added new filter
lwr_pre_insert_data
to modify data before database insertion - Increased field size for x_redirect_by from 100 to 255 characters
- Added new filter
lwr_should_log_redirect
to control which redirects are logged - Improved code documentation
- Initial release
Developed by Be API