Hi qtwrk,
I found a bug in the _htaccess_search() method which could be fixed using wp_normalize_path(). After this fix, the plugin works on Windows systems.
The _htaccess_search() function in LiteSpeed Cache tests, if the $star_path equals the $_SERVER[ ‘DOCUMENT_ROOT’ ]. Unfortunately the path separators are different for both paths on Windows systems. (Backslashes vs Slashes). The fix is to use the WordPress function wp_normalize_path(). This will normalize the paths and the condition will match.
Code on Github (_htaccess_search() – Line 194)
wp_normalize_path() modification:
// 2020-05-15 - CAMYA - Normalize start_path and DOCUMENT_ROOT (Windows fix)
if ( ! empty( $_SERVER[ 'DOCUMENT_ROOT' ] ) && wp_normalize_path($start_path) === wp_normalize_path($_SERVER[ 'DOCUMENT_ROOT' ]) ) {
return false ;
}
Another problem is the root folder, if $_SERVER[ ‘DOCUMENT_ROOT’ ] is not set. I guess, the function is also used from the WP-CLI. (Haven’t checked this by now).
My fix is to store the previous folder into a variable and check, if we reached the root folder. (old folder === new folder)
Here the complete modification:
private function _htaccess_search( $start_path )
{
while ( ! file_exists( $start_path . '/.htaccess' ) ) {
if ( $start_path === '/' || ! $start_path) {
return false ;
}
// 2020-05-15 - CAMYA - Normalize start_path and DOCUMENT_ROOT (Windows fix)
if ( ! empty( $_SERVER[ 'DOCUMENT_ROOT' ] ) && wp_normalize_path($start_path) === wp_normalize_path($_SERVER[ 'DOCUMENT_ROOT' ]) ) {
return false ;
}
// 2020-05-15 - CAMYA - Set filesystem root check helper variable (Windows fix)
if (!isset($start_path_before)) {
$start_path_before = $start_path;
}
$start_path = dirname( $start_path ) ;
// 2020-05-15 - CAMYA - Is this the filesystem root folder? (Windows fix)
if ($start_path_before === $start_path) {
return false;
}
// 2020-05-15 - CAMYA - Update path (Windows fix)
$start_path_before = $start_path;
}
return $start_path ;
}
I hope, it’s possible to add the wp_normalize_path() in the near future, because this will make the plugin work for many more people.
Best,
Andreas
-
This reply was modified 4 years, 6 months ago by camya.