Automattic / Automattic/wp-super-cache

Documentation - NGINX Rewrite Rules cause Duplicate Content issues in SEO

Open
#885 0 comments 1 reaction 0 assignees View on GitHub
[Plugin] Super Cache enhancement
Dominant language
PHP
Stars
436
Forks
130
Avg merge
15h 11m
Merged PRs (30d)
10

Description

Hello,

I use nginx and the defined rewrite rules to serve cache files found here:
https://wordpress.org/support/article/nginx/#wp-super-cache-rules

Problem:
Search engines were flagging my cached site with duplicate content.
http://example.com/url and
http://example.com/url/

Reproduce:
First visit http://example.com/url/ (to cache the file), then visit http://example.com/url (an expected WP redirect will not occur, the cached file will be served.)

The Issue:

In the line

`try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php?$args;`

The extra slashes cause file mismatches.

`$http_host` will contain a trailing slash by default.
`$cache_uri` will be either `url` or `url/` in my examples.

Because the instructed code has slashes, both requests will match a cached file and cause SEO problems.

The correct line should be delimited with NGINX ${variable} notation and not hard-coded slashes.

`try_files /wp-content/cache/supercache/${http_host}${cache_uri}index.html $uri $uri/ /index.php?$args;`

This will result in not-found file when `$cache_uri` is just `url` and allow WP to do it's standard redirect.

Hope this helps someone in the future.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the NGINX rewrite rules linked in the issue and compare the documented try_files line with the supplied replacement. Reproduce the /url/ and /url cases if possible; done when the documentation uses the corrected variable notation and the non-slash request can reach WordPress's standard redirect.

Written by the indexing model from the issue text.

Assessment

Tech stack
nginx, wordpress
Domain
devops, documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.