Block Search Robots
There are various methods to block robots from indexing your website. The Moz article Robots.txt and Meta Robots discusses some of the methods in greater detail.
If you would like to block robots using the meta noindex
robots tag, you can do so with the following technique:
- Setup a Craft multi-environment configuration
- Define a custom environment variable that you can use in your templates
- Conditionally output the
noindex
tag in all environments that are not the live environment using thesprout.seo.meta
variable
In the example below, the conditional statement assumes we have created an env
variable in our general.php
that is set to live
in our Live environment and not set to live in all of our other environments:
twig
{% if craft.config.env != 'live' %}
{% do sprout.meta.update({
robots: { 'noindex': 1, 'nofollow': 1 }
}) %}
{% endif %}