0
votes

I'm using a staticText route for my robots.txt in TYPO3 v10 (with default .htaccess file). The Text is delivered as expected, but the StatusCode in the Header is 404. I have no Idea how I can fix that, since there's no option in the staticText route to set the statusCode.

This is my code for the route (like described in the docs: https://docs.typo3.org/m/typo3/reference-coreapi/10.4/en-us/ApiOverview/SiteHandling/StaticRoutes.html):

routes:
  -
    route: robots.txt
    type: staticText
    content: |
    Sitemap: https://example.com/sitemap.xml
    User-agent: *
    Allow: /
    Disallow: /forbidden/
2

2 Answers

0
votes

I don't know if there's something wrong within the docs, but here's what I use:

routes:
  -
    route: robots.txt
    type: staticText
    content: "User-agent: *\r\nDisallow: /typo3/\r\n\r\nSitemap: https://example.com/sitemap.xml"

This is automatically generated when you use the Sites backend module.

Note: the contents of the robots.txt is a string with \r\n for line-breaks.

0
votes

Take a closer look at the documentation.

In YAML files, the indention is key. You have to indent your multiline content (beginning with "Sitemap:...").

routes:
  -
    route: robots.txt
    type: staticText
    content: |
      Sitemap: https://example.com/sitemap.xml
      User-agent: *
      Allow: /
      Disallow: /forbidden/

https://www.w3schools.io/file/yaml-multiline-strings/