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

As a hosting service, I want RUCSS requests to directly target the correct URL with trailing slashes to avoid additional traffic because of redirections

Open MathieuLamiot opened this issue 1 year ago • 0 comments

Context See here: we got traffic logs from a hosting service and a significant part of the traffic generated by RUCSS is due to redirections because the initial requested URL is missing a trailing slash.

[08/Feb/2024:17:18:05 +1100] "GET /practitioners/michael-thiel-paul?nowprocket=1&no_optimize=1 HTTP/2" 301 0 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36"
[08/Feb/2024:17:18:06 +1100] "GET /practitioners/michael-thiel-paul/?nowprocket=1&no_optimize=1 HTTP/2" 200 41437 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36"

The URL is re-written: /practitioners/michael-thiel-paul -> /practitioners/michael-thiel-paul/

Trailing slashes are usually added or not through permalink rules.

Expected behavior URLs that the plugin sends to the SaaS should correctly contain or not trailing slashes, according to the permalink structure defined in WP.

How to reproduce

https://github.com/wp-media/wp-rocket/assets/15233030/8c13a7fa-5dd6-4d0d-997a-d2cdffbe7984

  • Get or setup a website with WP Rocket and WP permalinks configured with a trailing slash. For example, gamma rocketlabsqa website is currently defined this way.
  • Make sure RUCSS is enabled on the website.
  • Check the table wp_wpr_rucss_used_css in the DB for jobs that were completed less than 7 days ago. If there are not any, clear used CSS and browse a bit to trigger some RUCSS jobs.
  • Retrieve the ULID part of a recently completed job (the string after the '--' in the Job Id column) where the job Id begins with LIVE2-CPH3-PROD: It means the job was processed by a group.One server and the job data is available in Metabase.
  • Go to Metabase and create a new native query on SaaS director DB. Use this query:
with result as (select * from saas_job 

    where "jobIdInQueue" = '01HNZ8V0T6CMTQ25ENY1K95D60' limit 1)
    
    select * from result join saas_optimizationrequest on result."optimizationRequest_id" = saas_optimizationrequest.uuid

Just replace the ULID by the one of your job.

Check in the result, there should be a column named URL. IT does not have the trailing slash. Open this URL in a browser and you will see the 301 HTTP Code.

Acceptance Criteria

  • Perform the "How to reproduce" with clearing cache & used CSS and browsing a bit to regenerate jobs. The URL at the end must have the trailing slash.
  • Re-do the same but with permalinks configured without a trailing slash. The URL at the end must have no trailing slash.

MathieuLamiot avatar Feb 08 '24 12:02 MathieuLamiot