nerdErg

Adding robots.txt to a grails app

01 June 2019

Adding robots.txt to your Grails app I just wanted to add a robots.txt file to Groupie, easy enough you say, as a matter of fact yes it is :-)

What I did was to add the following line to UrlMappings.groovy in the Configuration folder:-

UrlMappings.groovy
"/robots.txt" (view: "/robots")

then create a robots.gsp file in the Views and Layouts folder that looks something like this:

robots.gsp
<%@ page contentType="text/plain;charset=UTF-8" %>User-agent: *
Disallow: /blah/

Note no new-line before User-agent: * here is to remove the blank line left by the <%@ page…​%> in the file.

That’s it.