wp-media / wp-rocket

Performance optimization plugin for WordPress
https://wp-rocket.me
GNU General Public License v2.0
701 stars 218 forks source link

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

Closed vmanthos closed 4 months ago

vmanthos commented 2 years ago

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

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)

DahmaniAdame commented 2 years ago

Related - https://secure.helpscout.net/conversation/1805696754/329611/

$host is pointing to a totally different name.

https://github.com/wp-media/wp-rocket/blob/7efe5e0c685884f99cf54e6fc6b178a1a98fc256/inc/classes/Buffer/class-config.php#L194

DahmaniAdame commented 2 years ago

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

DahmaniAdame commented 1 year ago

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

piotrbak commented 4 months ago

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