Score:1

drupal-scaffold composer append robots.txt

us flag

We recently upgraded to Drupal 9.3.0 with the composer layout. Each time we execute composer update the contents of robots.txt is overlayed with the file located in core/assets/scaffold/files/robots.txt. We would like to append the default robots.txt with project unique data.

I included the following in composer.json per the documentation I found:

    "extra": {
        "drupal-scaffold": {
            "locations": {
                "web-root": "web/"
            },
            "file-mapping": {
               "[web-root]/robots.txt": {
               "append": "assets/robots.txt.append"
               }
            }
        },

I hesitate to create the file core/assets/scaffold/files/robots.txt.append as we have been trained for sometime to not change/add any files in the core/ directory. Where should robots.txt.append be placed to make this work?

Score:2
cn flag

The path is relative to your project root (where composer.json lives), so in your example create a folder called /assets in the root, i.e. a sibling of /web.

If your question is more whether there's a particular path you should place it at, then the answer is: not especially. The file isn't part of the web app itself, so common sense might say don't put it in /web, but really it's up to you.

Just make sure it's placed somewhere that won't be overwritten during composer updates, and that it's included with your git commits (so not sites/default/files etc), and you'll be fine.

Greg Sims avatar
us flag
I created the file at ```assets/robots.txt.append``` where ``assets/``` is a sibling with ```web/```. All is working well! Thanks
Kevin avatar
in flag
You can also not scaffold it and add the robots txt module.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.