I've got a website that has a resource center, news center and blog where each of those sections has a high quantity of assets that can be filtered by topic / type / date, etc. Additionally, due to the quantity of assets, we're using pagination to spread the assets across multiple pages.

All of the filtering and pagination creates a variety of worthless but currently crawlable URLs that we'd like to hide from the search engines.

I'm attempting to deploy the meta name="robots" content="noindex, follow" tag to all of the paginated / filtered URLs while keeping the overview pages indexed. It seems that the most logical way to do that is based on a consistent URL string that appears in both pagination and filtering instances.

How can I add a rule within my template that will insert the meta tag based on whether or not a string exists in the current URL appearing in a user's browser?

Any help would be much appreciated. Thanks!

1 Answer 1


If the string you're looking for is part of the URI segment, then something like:

{% if (craft.request.getSegment(3) == 'mySpecialKey') %}
    <meta name="robots" content="noindex, follow">
{% endif %}

(Adjusting the 3 for whichever part of the segment it's actually in.

Or if it's part of the querystring, then use craft.request.getParam('mySpecialKey').

  • You could also compare against getPageNum in the conditional: {% if (craft.request.getPageNum() != 1) %}.
    – carlcs
    Commented May 29, 2015 at 9:02
  • Thanks, gents! The portion of the URL that I'd like to target is actually a ? as part of a query string. Essentially, I'd like the rule to be applied whenever a query string exists.The getSegment method above seems to work at targeting a portion of a static URL but is not working when I try to target the ? in the query string. Same for the getParam method. Is there a way that I can make a similar if / then rule based on whether or not a query string exists?
    – dpayne
    Commented May 29, 2015 at 15:46
  • 1
    Both getParam('key') and getQuery('key') should return from the querystring.
    – Brad Bell
    Commented May 29, 2015 at 17:31
  • Thanks, Brad! I was able to get it working with your help.
    – dpayne
    Commented May 29, 2015 at 21:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.