It may also be useful to configure nofollow for your staging environment if you use it. Not sure if there is a use case for indexing an intermediate site .... therefore, if you agree, you can use these steps to block it.
If you use Tomcat, set an environment variable such as NOFOLLOW = true -> see here, for example: TOMCAT_OPTS, environment variable and System.getEnv ()
Next, as @doelleri mentioned, install urlMappings
Urlmappings
//Robots.txt "/robots.txt"(controller: 'robots', action:'robots')
Then use robotsController to determine the environment variable that you set in your staging cat.
Robotscontroller
def robots() { if (System.getenv('NOFOLLOW') == 'true') { def text = "User-agent: *\n" + "Disallow: /cgi-bin/ \n" + "Disallow: /tmp/ \n" + "Disallow: /junk/ \n" + "Disallow: /admin/ \n" + "Crawl-delay: 5 \n" + "Sitemap: https://www.example.com/sitemap.xml" render(text: text, contentType: "text/plain", encoding: "UTF-8") } else { render(status: 404, text: 'Failed to load robots.txt') } }
robots.gsp
<%-- Content rendered from controller -> so leave blank :) --%>
source share