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

Caching/optimizations aren't applied when HTTP_HOST is different from the home_url()

Open vmanthos opened this issue 3 years ago • 2 comments

Before submitting an issue please check that you’ve completed the following steps:

  • Made sure you’re on the latest version ✅3.10.5.1
  • Used the search feature to ensure that the bug hasn’t been reported before ✅

Describe the bug

In cases where the HTTP_HOST is different from the site's URL, as that's returned by home_url(), caching and optimizations do not work because WP Rocket's configuration file cannot be found here: https://github.com/wp-media/wp-rocket/blob/7efe5e0c685884f99cf54e6fc6b178a1a98fc256/inc/classes/Buffer/class-tests.php#L195-L202

This is because the file path/filename of the configuration file we are looking for is different compared to the one we store the configuration file: https://github.com/wp-media/wp-rocket/blob/7efe5e0c685884f99cf54e6fc6b178a1a98fc256/inc/functions/files.php#L163-L177

In the class-tests.php we rely on HTTP_HOST: https://github.com/wp-media/wp-rocket/blob/7efe5e0c685884f99cf54e6fc6b178a1a98fc256/inc/classes/Buffer/class-config.php#L194

while when creating the configuration on home_url().

WPEngine Example

Per @DahmaniAdame WPEngine doesn't allow subfolder WordPress installation.

As a workaround, they allow installing on a subdomain and mapping it to a subfolder.

This results in HTTP_HOST ≠ home_url().

To Reproduce

Although I haven't tried this, using WPEngine's example, i.e. creating a subfolder installation and redirecting that to a subdomain, should allow reproducing this: How To Redirect Subfolder To Subdomain

Expected behavior

Currently, after figuring this is the issue, the solution we have is to use the config cloner helper plugin.

Caching/optimizations should work automatically even when HTTP_HOST is different from the site's URL.

Additional context

We should use the same approach both in the configuration file's creation, and when checking for it in the Buffer class.

According to @Tabrisrp:

the only part that can be modified is the one when storing the config file because the other one WP is not loaded and we won’t have access to home_url() for example

Slack convo: https://wp-media.slack.com/archives/C43T1AYMQ/p1639636868049600 Ticket: https://secure.helpscout.net/conversation/1717861502/312768/

Backlog Grooming (for WP Media dev team use only)

  • [ ] Reproduce the problem
  • [ ] Identify the root cause
  • [ ] Scope a solution
  • [ ] Estimate the effort

vmanthos avatar Dec 17 '21 07:12 vmanthos

Related - https://secure.helpscout.net/conversation/1717861502/312768/ Any progress on this one?

DahmaniAdame avatar Sep 09 '22 12:09 DahmaniAdame

Related - https://secure.helpscout.net/conversation/2079131123/384774

DahmaniAdame avatar Dec 02 '22 05:12 DahmaniAdame

This is not something that can be implemented soon. We might reopen this in the future.

piotrbak avatar Jul 10 '24 17:07 piotrbak