Keep Bots Out of Redirection's 404 Log
Stops the Redirection plugin from logging 404s caused by crawlers and vulnerability scanners (wp-login probes, .env and .php file hunts), so the log shows only real broken links.
Opens WPIDE on
Code
$wpide_noise = array( '.env', 'wp-config', '.php', 'xmlrpc', '/.git', 'phpmyadmin', 'wlwmanifest' ); // URL fragments to ignore.
add_filter( 'redirection_404_data', function ( $data ) use ( $wpide_noise ) {
$agent = isset( $data['agent'] ) ? strtolower( (string) $data['agent'] ) : '';
$url = isset( $data['url'] ) ? strtolower( (string) $data['url'] ) : '';
if ( preg_match( '/bot|crawl|spider|scan|curl|python|wget/', $agent ) ) {
return false;
}
foreach ( $wpide_noise as $fragment ) {
if ( false !== strpos( $url, $fragment ) ) {
return false;
}
}
return $data;
} );
Notes
Add your own patterns to $wpide_noise.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.