Hi JenDeg.
There was a problem with my answer and I thought it would be better to put the code together, so I created the following code.
Problems with my solutions:
- Shopify’s robots.txt has the entire search result set to Disallow
- Search engines cannot recognize a noindex on the search results page
Necessary Action:
- Remove Disallow for search results from robots.txt
- Output noindex to necessary pages
■ Caution!
I am not good at writing English, so there may be some writing errors.
Here is how to do it, but failure to do so can cause serious problems.
It is also possible that my code is incorrect.
So if you are not confident in your judgment or skills, please consult a Shopify partner or expert.
■ How to remove Disallow for search results from robots.txt
Be sure to check the following:
Create robots.txt.liquid and add two lines to the original code as follows.
# we use Shopify as our ecommerce platform
{%- comment -%}
# Caution! Please read https://help.shopify.com/en/manual/promoting-marketing/seo/editing-robots-txt before proceeding to make changes to this file.
{% endcomment %}
{% for group in robots.default_groups %}
{{- group.user_agent -}}
{% for rule in group.rules %}
{%- unless rule.directive == 'Disallow' and rule.value == '/search' -%}
{{- rule -}}
{%- endunless -%}
{% endfor %}
{%- if group.sitemap != blank -%}
{{ group.sitemap }}
{%- endif -%}
{% endfor %}
Code part added:
- {%- unless rule.directive == ‘Disallow’ and rule.value == ‘/search’ -%}
- {%- endunless -%}
■ How to output noindex to necessary pages
As an example, you can summarize the code for noindex in the head tag as follows
{%- liquid
assign flag_noindex = false
case request.path
when '/search'
assign flag_noindex = true
when '/collections/vendors'
if collection.all_products_count == 0
assign flag_noindex = true
endif
endcase
-%}
{% if flag_noindex %}
{% endif %}
Operating conditions:
- Output noindex in search results (even if there are more than 1 results)
- Output noindex when there are 0 results in vendor
However, if the status code 404 is returned when there are 0 cases on the vendors page, the noindex for the vendors page is not very useful.
As a small possibility, it may serve as a precautionary measure, though.
Just to be sure, check for yourself that the code works as intended!