How to handle page triggers on pages without pagination? #14072
-
The basic problem: Page triggers (e.G. A client’s Sistrix report said that the meta description was the same for the URLs This site has a My first instinct was to insert Is there another solution? Given that there are matrix blocks with relational fields that can be optionally paginated in my content-builder matrix field, the solution above doesn't feel very comfortable. Pages that include a paginated list of items should be available as separate pages to search engines, while pages without paginated items should all point to the same canonical URL. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
How is the Sistrix report finding out about these other URIs to begin with? Is something liking to them? Theoretically if nothing links to them and they’re not part of a site map, they shouldn’t be a problem.
You should be doing that regardless. There are multiple ways to access the same generated page with distinct URLs in Craft, beyond adding a page number ( |
Beta Was this translation helpful? Give feedback.
-
We have this issue too. While this is not a high priority issue for us, it seems to make sense that an invalid pagination URL should generate an error. The |
Beta Was this translation helpful? Give feedback.
-
If you really want to prevent the 200 status code for "invalid" pagination URLs, you can use a little bit of Twig to manually return a 404 whenever there's a Something like this could go at the top of your page template (or even in your Twig layout, if your site doesn't use pagination anywhere): {% if craft.app.response.statusCode == 200 and craft.app.request.absoluteUrl matches "/#{craft.app.config.general.pageTrigger}[\\d\\.]+(\\/.*)?$/" %}
{% exit 404 %}
{% endif %} Basically what that does is to use a regular expression to test if the requested URL ends with the page trigger followed by a number (and an optional trailing slash); terminating the request if that's the case. If your page trigger is configured to use a query parameter, something like this would probably be more appropriate: {% if craft.app.response.statusCode == 200 and craft.app.request.queryParams[craft.app.config.general.pageTrigger|trim('?')]|default %}
{% exit 404 %}
{% endif %} Finally, if your page template does use pagination, but you want to throw a 404 if the requested URL has a page trigger higher than the total amount of pages, you could do something like this: {% paginate query as pageInfo, entries %}
{% if craft.app.request.pageNum > pageInfo.totalPages %}
{% exit 404 %}
{% endif %} |
Beta Was this translation helpful? Give feedback.
How is the Sistrix report finding out about these other URIs to begin with? Is something liking to them? Theoretically if nothing links to them and they’re not part of a site map, they shouldn’t be a problem.
You should be doing that regardless. There are multiple ways to access the same generated page with distinct URLs in Craft, beyond adding a page number (
index.php?p=about-us
,about-us?foo=bar
, etc.). SEOmatic, and presumably other SEO plugins, will add thecanonical
tag for you, along with JSON-LD data and other SEO tuning.