mercredi 30 décembre 2020

Show robots.txt file at domain.com/robots.txt instead of domain.com/context/robots.txt in Spring Java web app

I'm trying to add a robots.txt file to my Spring Java web application, but when I put the file in the webapp folder, the text is only visible through localhost:8000/context/robots.txt instead of localhost:8000/robots.txt (the url that google crawler would check), where I receive a 404 error. I've tried putting the robots.txt file at src, WEB-INF, the project's root folder, etc. with the same results.

I've also tried changing my application-context.xml redirecting "/robots.txt" to my file with <mvc:resources mapping="/robots.txt" location="/robots.txt" order="0"/> for all the previous locations and still doesn't work. The index page of my app would be domain.com/context/firstpage.ac so every page is accessible under that context and as I said also the robots.txt file is showed there when I put it on the webapp folder.

Is there any way to separate my robots file from the others and put it at localhost:8000/robots.txt or it isn't possible since my app is deployed under that specific context? It's my first time with a java web app front and I'm completely unfamiliar with all of this, I've tried all the possible solutions that I've found (even though I don't fully understand any of them) and nothing works so any help or hint on this would be very appreciated!

folder-structure




Aucun commentaire:

Enregistrer un commentaire