Automattic / Automattic/wp-super-cache

Enhancement: Strip ignored tracking query parameters via mod_rewrite

Open
#1,018 1 comment 0 reactions 1 assignee Assigned to @donnchawp View on GitHub
[Plugin] Super Cache
Dominant language
PHP
Stars
436
Forks
130
Avg merge
15h 11m
Merged PRs (30d)
10

Description

### Impacted plugin

Super Cache

### What

Generate a mod_rewrite block so “Ignore tracking parameters” works in Expert/mod_rewrite mode by treating configured tracking params as non-cache-key (no redirect).

### How

The "Ignore tracking parameters" setting (`wpsc_ignore_tracking_parameters`) currently has no effect in Expert/mod_rewrite mode. The generated .htaccess rules require `%{QUERY_STRING} ^$` before serving a static cached file. Any URL with tracking parameters like ?fbclid=abc or ?utm_source=twitter fails that condition and falls through to PHP.

The PHP cache layer then strips the parameters and serves from the PHP-level cache, which works correctly but defeats the purpose of Expert mode. Every social media referral, every email campaign click hits PHP instead of being served as a static file by Apache. On high-traffic sites, social referrals and campaign links can easily represent the majority of incoming traffic. All of that traffic is currently taking the slow path.

Proposed fix: Instead of issuing a 301 redirect, adjust the generated supercache “serve static file” condition so that requests are eligible for the static cache path when the query string is either empty or contains only configured tracking parameters. That preserves the user-visible URL (no redirect) while letting Apache serve the static file.

Replace the current requirement:
```
RewriteCond %{QUERY_STRING} ^$
```
with:
```
RewriteCond %{QUERY_STRING} ^$ [OR]
RewriteCond %{QUERY_STRING} ^(fbclid|gclid|utm_source|utm_medium|utm_campaign|...)= [NC]
```

The pattern is built dynamically from the same `wpsc_tracking_parameters` array already in the config (matching “only ignorable params”, allowing multiple keys separated by &). With this change, URLs containing only ignored tracking parameters follow the existing static-cache rewrite path instead of falling through to PHP.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.