Persist URL fragment during client-side mobile redirection and guard against infinite redirect #5775
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5767.
This fixes an issue which can occur when a caching plugin is failing to vary the cache by query parameters. This can result in cache pollution, where a non-AMP page is cached and served for both non-AMP URLs and AMP URLs alike, and vice-versa. When a non-AMP page is served for an AMP URL, mobile redirection can end up endlessly attempting to redirect to the AMP version, even though the user is already at the AMP URL. So the fix here is merely to check that the user is not at the AMP URL already. This fixes a symptom of a misconfigured caching plugin, although the underlying cache misconfiguration issue remains to be addressed by the site owner.
This PR also fixes a related issue I discovered where client-side mobile redirection was not persisting the URL fragment. For example, if attempting to go to
/#colophon
then redirection would result in the user going to/?amp=1
instead of the expected/?amp=1#colophon
.Before
before2.mov
After
after.mov
Checklist