-
Notifications
You must be signed in to change notification settings - Fork 638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.x]: Cache includes links with x-craft-live-preview in query params #15586
Comments
Worth mentioning that URLs with These URLs are also eligible to be indexed, as Craft only sets the |
Hi both, thanks for reporting and all the details! I raised a PR for the caching issue. In terms of caching, a request with an invalid or expired token would still return If the token param is omitted from generated URLs (e.g., if invalid or expired), but the preview param is present in the request, that preview param will be added to the generated URLs, and the |
Thanks @i-just! Any idea when someone will merge this? URLs with the preview token query parameter are now being indexed by Google and it's spreading every hour. |
This was driving me crazy! I finally ended up adding the following redirect snippet to my if (@$_GET['x-craft-preview']):
unset($_GET['x-craft-preview']);
$parsed_url = parse_url($_SERVER['REQUEST_URI']);
$redirect = $parsed_url['path']
. (!empty($_GET)
? '?' . http_build_query($_GET)
: '');
exit(header("Location: $redirect"));
endif; Can't wait for this to get resolved so I can drop it. |
I think another wrinkle to this (that should maybe be a separate issue, but here goes) is that unlike the token param (which is omitted from generated URLs if invalid) the preview param is rendered back out verbatim for all URLs. While it's great that preview requests will no longer be cached, this detail still makes me a little bit uneasy. Considering that – AFAIK – preview param values are just random strings, would it make sense if Craft generated a new random string to use for the generated URLs' preview params, instead of using the value from the request URL? |
@nikolowry I did this and will probably have to keep this because Google already indexed 100+ pages and I will never get rid of them:
|
Craft 4.11.5 and 5.3.6 are out with a fix for this, via #15589. |
Craft 4.12.0 and 5.4.0 are out now with a related change: Craft now sends a |
What happened?
Description
If you open preview mode on an entry that has no changes, the token is not in the URLs of links in the preview mode, but the x-craft-live-preview token is.
If you use
{% cache %}
in your templates, this part will be cached with thex-craft-live-preview
added to all links in the cached part of code.The reason that it's cached, is probably because there is no token:
cms/src/services/TemplateCaches.php
Line 371 in 4439082
This way, you will end up with
x-craft-live-preview
tokens in the Google index (and that's precisely what is happened now)Steps to reproduce
Expected behavior
No x-craft-live-preview-URLs on a production website
Actual behavior
Craft CMS version
5.3.4
PHP version
8.3
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions
The text was updated successfully, but these errors were encountered: