How to add robots.txt

Enonic version: 6.5.4


I have application which is published.
Is there any possibility to add robots.txt to the applications ?

You could create a controller mapping to handle the robots.txt

Add this in site.xml:

  <mapping controller="/site/robots/robots.js">

Create /site/robots/robots.js file in the app:

var ioLib = require('/lib/xp/io');

exports.get = function (req) {
    var robotsFile = ioLib.getResource('/site/robots/robots.txt').getStream();
    var robotsText = ioLib.readText(robotsFile);

    return {
        contentType: 'text/plain',
        body: robotsText

Then create your robots.txt file in the same app: /site/robots/robots.txt

This will work in 6.6, but unfortunately there is a bug in 6.5 that requires that there exists a content in the path for the mapping to work. So in 6.5 you also have to create a content and name it “robots.txt” just under your Site content. It can be anything, even if it is not accessible, like a folder.

Hope this helps. We are planing to release 6.6 next week.


Thank you,

At 6.5 I’ve done it in next way: = localhost
mapping.r.source = /robots.txt = /PATH_TO_SERVICE/robots-service = localhost
mapping.f.source = /favicon.ico = /PATH_TO_SERVICE//favicon-service`


I smell a demand for an app that can do this… or perhaps some modifications to one of the existing SEO apps that are on the Enonic Market? Just a friendly reminder to anyone who has some free time and inspiration on their hands :wink: