Last active
January 21, 2017 12:21
-
-
Save aliaghdam/2d04daf83317d94b85265b60e7c6fa15 to your computer and use it in GitHub Desktop.
ByPass CloadFlare 404 pages in WordPress - Force WP to show Theme 404 Page in CloadFlare!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'status_header', 'better_studio_bypass_cloadflare_404_status_header', 100, 2 ); | |
function better_studio_bypass_cloadflare_404_status_header( $status_header, $code ) { | |
// Detect 404 page | |
if ( $code === 404 ) { | |
// Return normal content type when user agent in not set | |
if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { | |
// Return normal content type for real visitors | |
// When the $status_header was empty then the http_response_code will be rejected by PHP | |
// http://php.net/manual/en/function.header.php | |
return ''; | |
} | |
// Crawlers list | |
$crawlers_agents = array( | |
'googlebot', | |
'msn', | |
'rambler', | |
'yahoo', | |
'abachobot', | |
'accoona', | |
'aciorobot', | |
'aspseek', | |
'cococrawler', | |
'dumbot', | |
'fast-webcrawler', | |
'geonabot', | |
'gigabot', | |
'lycos', | |
'msrbot', | |
'scooter', | |
'altavista', | |
'idbot', | |
'estyle', | |
'scrubby', | |
'ia_archiver', | |
'jeeves', | |
'slurp@inktomi', | |
'turnitinbot', | |
'technorati', | |
'findexa', | |
'findlinks', | |
'gaisbo', | |
'zyborg', | |
'surveybot', | |
'bloglines', | |
'blogsearch', | |
'pubsub', | |
'syndic8', | |
'userland', | |
'become.com', | |
'baiduspider', | |
'360spider', | |
'spider', | |
'sosospider', | |
'yandex', | |
); | |
$user_agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); | |
// Detects search engine crawlers to return 404 for them! | |
// It enables Google Webmaster tools 404 page logs | |
foreach ( $crawlers_agents as $crawler ) { | |
if ( strpos( $user_agent, $crawler ) ) { | |
return $status_header; | |
} | |
} | |
// Return normal content type for real visitors | |
// When the $status_header was empty then the http_response_code will be rejected by PHP | |
// http://php.net/manual/en/function.header.php | |
return ''; | |
} | |
return $status_header; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment