legacy-knowledge-base
公開されました Jun. 30, 2025

Unable to read the content for custom_robots.txt file

written-by

Jose L. Bango

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

legacy-article

learn-legacy-article-disclaimer-text

Issue

  • I am getting the following message in my log file:
    [RobotsUtil:47] Unable to read the content for custom_robots.txt
  • However, the same does not happen in other environments. What can be the reason?

Environment

  • Liferay 7.4

Resolution

Why can that error message be thrown?

  • That exception is thrown in RobotsUtil.java class. Either for robots.txt without sitemap, or with sitemap.
  • In the first case (without sitemap):
    • It means that layoutset is null when reaching RobotsUtil.java#L40
    • Therefore, it tries to get the file set in robots.txt.without.sitemap property.
      • If the file cannot be found, it prints the aforementioned error message.
  • In the second case (with sitemap):
    • It means that layoutset is not null in RobotsUtil.java#L40
    • It retrieves the robots.txt with sitemap here:
      • From the layoutset's settings, if they have been already modified.
      • Otherwise, from the file indicated by the robots.txt.with.sitemap property.
        • If the file cannot be found, it prints the aforementioned error message.

Why is (or is not) layoutset null in RobotsUtil.getRobots() method?

Where should I place my custom robots.txt file?

  • If you want to leverage robots.txt.without.sitemap or robots.txt.with.sitemap properties, take into account that Liferay tries to get those files using the ClassLoader as base path. (see RobotsUtil.java#L43).
  • For example, when using Tomcat, your custom robots.txt file should be placed in tomcat/webapps/ROOT/WEB-INF/classes/ (or a relative path from there).

Additional Information

did-this-article-resolve-your-issue

legacy-knowledge-base