Block Spam Internal Site Search Indexed in Google and Redirect to Specific Page

97 Views Asked by At

Recently, we’ve been bombarded with thousands of spam search queries via our internal search, and some of them have been indexed by Google, despite our attempts to block them using the ‘no-follow’ attribute in Yoast. Additionally, a significant amount of data is showing up in the ‘no-index’ status (blocked by robot.txt).

To address this issue, I’ve implemented a solution in our child theme’s function.php file. Now, all these spam-related search terms are being redirected to our default search page.

I have a couple of questions:

Is this the correct approach to stop the spam internal searches? Is it beneficial or bad for SEO? I’ve experienced a drop in our rankings due to these spam attacks. Are there any other techniques you would recommend to mitigate this problem?”

The Code I’m using is below:

function rlv_block_search( $query ) {
if ( ! empty( $query->query_vars['s'] ) ) {
$blacklist = array( '大奖', 'q82', 'PG99.Asia', 'qqline88th.com', 'joker123.net'); // add blacklist entries here; no need for whole words, use the smallest part you can
foreach ( $blacklist as $term ) {
if ( mb_stripos( $query->query_vars['s'], $term ) !== false ) {
wp_redirect( "https://www.example.com/?s=", 301 );
exit();
}
}
}
}
0

There are 0 best solutions below