Created
May 24, 2019 11:55
-
-
Save vmanthos/e2952f7c41eb26ddc446b9800c4427fe to your computer and use it in GitHub Desktop.
Skip WordPress handling 404 on static files to avoid lack of performance.
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
<?php | |
/** | |
* Plugin Name: Speed Up 404 Static File | |
* Description: Skip WordPress handling 404 on static files to avoid lack of performance. | |
* Author: GeekPress | |
* Licence: GPLv2 or later | |
* */ | |
$path = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ); | |
$path = explode( '/', $path ); | |
$abspath = explode( '/', ABSPATH ); | |
$path = implode('/', array_diff( $path, $abspath )); | |
$extension = pathinfo( $_SERVER['REQUEST_URI'], PATHINFO_EXTENSION ); | |
$extensions = [ | |
'php' => 1, | |
'html' => 1, | |
'json' => 1, | |
'xml' => 1, | |
]; | |
if ( strlen( $extension ) > 0 && ! isset( $extensions[$extension] ) && ! file_exists( ABSPATH . $path ) ) { | |
status_header( 404 ); | |
die(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment