wp-rocket-cli icon indicating copy to clipboard operation
wp-rocket-cli copied to clipboard

htaccess regeneration not working from CLI with Bedrock

Open Sidlegionair opened this issue 5 years ago • 3 comments

Hi,

The regeneration command does not work when running bedrock (https://roots.io/bedrock). It fails to detect the correct htaccess path from CLI and then it will stop to work here (htaccess.php line 33)

$htaccess_file = get_home_path() . '.htaccess';

if ( ! rocket_direct_filesystem()->is_writable( $htaccess_file ) ) {
	// The file is not writable or does not exist.
	return false;
}

Sidlegionair avatar Jul 15 '20 13:07 Sidlegionair

Note for grooming: Check possible connection with #22

iCaspar avatar Dec 01 '20 20:12 iCaspar

Reproduce the problem ✅

Reproduced on local installation under Flywheel + Bedrock

Identify the root cause ✅

The root cause is related to get_home_path() which brings the / path. Based on Bedrock documents, it seems that .htaccess file needs to be located under: web/.htaccess and this is the issue. WP Rocket uses $htaccess_file = get_home_path() . '.htaccess'; which will identify the path to .htaccess file as : /.htaccess which is not accurate.

UPDATE: IT seems this is only from CLI due to wrong ABSPATH coming from Bedrock

The issue is coming from this line: $home_path = substr( $_SERVER['SCRIPT_FILENAME'], 0, $pos ); from get_home_path() -> file.php WP class From CLI it seems that SCRIPT_FILENAME = usr/bin/local/wp which will break totally the home_path and also our htaccess path.

Scope a solution ✅

A possible solution is that from CLI to map the get_home_path() without any SCRIPT_FILENAME and modify also flush_rocket_htaccess() function to accept the full path to htaccess file and bypass the default get_home_path()

@wp-media/php what do you think? Did I missed something?

Estimate the effort ✅

Effort [S]

crystinutzaa avatar Dec 04 '20 14:12 crystinutzaa

@Sidlegionair @crystinutzaa Can you retry this issue with v1.2 of the CLI?

One of the changes to fix #22 Could be also fixing this issue.

remyperona avatar Jan 27 '21 21:01 remyperona