Where to put robots.txt in tomcat 7?

I am using Tomcat 7 to host my application. I used the ROOT.xml file under the name tomcat-home \ conf \ Catalina \ localhost

<Context docBase="C:\Program Files\Apache Software Foundation\Tomcat 7.0\mywebapp\MyApplication" path="" reloadable="true" /> 

This download my webapp in the root context.

But now I'm confused about where to put the robots.txt and sitemap.xml files. When I put under C: \ Program Files \ Apache Software Foundation \ Tomcat 7.0 \ mywebapp \ MyApplication, it does not appear.

I also tried placing it inside C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT , just in case. But nothing works. I still get 404 not found. Someone can advise.

ps My web application is working fine. Just my robots.txt file is not available.

EDIT

My web.xml file:

  <filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy </filter-class> </filter> <filter-mapping> <filter-name>springSecurityFilterChain</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> 
+3
source share
3 answers

It should be in your context directory

mywebapp\MyApplication

where you will have your web-inf directory, index.html, etc.

UPDATE:

According to our discussion, all URLs are handled by Spring MVC DelegatingFilterProxy, so you need to somehow exclude * .txt from this filter, maybe by expanding DelegatingFilterProxy and setting this filter in web.xml

SOLUTION: I can static server content through this hack in Spring MVC:

 <mvc:resources mapping="/robots.txt" location="/robots.txt" order="0"/> 

Saved me a lot of headache. :) Writing this for someone else to take advantage of.

+3
source

Just put robots.txt in Tomcat_DIR/webapps/ROOT/

+3
source

I have the same problem: I do not measure where I put my robots.txt or configure <mvc:resources mapping="/robots.txt" location="/robots.txt" order="0"/> every request so that robots.txt returned status 404.

The problem is that I use both Spring MVC and Backbone.js MVC on the client side, which has its own routing. Therefore, I could not configure <url-pattern></url-pattern> to serve both MVCs.

The only quick and ugly solution I found here is to handle requests in /robots.txt as a request in Spring MVC

 @RequestMapping(value = "/robots.txt", produces = {"text/plain"}, method = RequestMethod.GET) @ResponseBody public String getRobotsTxt() { return "User-agent: *" + "\n" + "Allow: /js/views/*.js" + "\n" + "Allow: /js/*.js" + "\n" + "Allow: /css/*.css" + "\n" + "Allow: /css/*.png" + "\n" + "Disallow: /cgi-bin" + "\n" + "Sitemap: http://blabla/sitemap.xml"; } 
0
source

Source: https://habr.com/ru/post/921995/


All Articles