Maintain SEO for filterable store pages
On this page
Search engines treat each unique URL as a separate page. On an ecommerce site, filtering and sorting add query parameters to the URL, so the same product category page can be reached at many URLs, for example ?sort=price&page=3. Search engines see those as separate pages showing duplicate content, which lowers your ranking.
The solution
Use a global variable to tell search engines to ignore the extra parameters in the URL.
The current_request global variable
current_request is a global you can use in your Liquid. It returns a request object describing how the current page was accessed. It offers many attributes; these three are the ones used below.
| Attribute | Returns | Example |
|---|---|---|
fullpath |
Everything after the domain, including the query string | /products?page=3 |
path |
Everything after the domain, up to the ? |
/products |
query_string |
Everything after the ?, if there is one |
page=3 |
When a page is accessed with query parameters, you may want to show different content. There are a few ways to do this.
Using fullpath
{% if current_request.fullpath == "/current-offers" %}
This content will show if there the full path exactly matches "/current-offers"
This will not match: "/current-offers?sort=price"
{% else %}
This content will show in all other circumstances
{% endif %}
Using query_string
{% if current_request.query_string == "" %}
This content will show if there are no query parameters
{% else %}
This content will show if the page was requested with query parameters
{% endif %}
Using a combination of path and query_string
This method is useful when you want to change the content based on which query parameters were used.
``` {% if current_request.path == “/current-offers” %} We know we’re on the Current Offers page We don’t yet know if it was accessed with query parameters
{% if current_request.query_string != “” %} Ok so the page was accessed with query params
{% assign params = current_request.query_string | prepend: "&" %}
{% if params contains "&page=" %}
The page was accessed with the query parameter: page!
{% elsif params contains "&sort=" %}
The page was accessed with the query parameter sort!
{% else %}
The page was accessed with some other query parameters! ¯\_(ツ)_/¯
{% endif %} {% else %}
The page was not accessed with any query parameters {% endif %} {% endif %} ```
Was this article helpful?
Thanks for your feedback! It helps us improve our docs.