새소식

Framework/🍃 Spring

Spring boot에서 robots.txt와 sitemap.xml 적용하는 방법

  • -
728x90

안녕하세요. 팀드모네입니다.

오늘은 Spring boot에서 robots.txt와 sitemap.xml 적용하는 방법을 공유드립니다.

 

1. robots.txt와 sitemap.xml 생성 작업 수행

해당 파일은 아래의 URL에서 작업하실 수 있습니다.

 

robots.txt 자동 생성 사이트 : https://ciroapp.com/ko/free-tools/robots-txt-file-generator

sitemap.xml 자동 생성 사이트 : https://www.xml-sitemaps.com/

 

2. robots.txt와 sitemap.xml 을 templates에 배치

작업이 완료된 해당 파일들을 resources > templates에 위치시킵니다.

 

3. RequestMapping 작성

적당한 Controller에 아래의 소스코드를 기입합니다.

저의 경우 MainController.java 라는 곳에 기입하였습니다.

    /* robots.txt 처리 */
    @RequestMapping(value = "/robots.txt")
    public String robots() {
        return "robots.txt";
    }

    /* sitemap.txt 처리 */
    @RequestMapping(value = "/sitemap.txt")
    public String sitemap() {
        return "sitemap.xml";
    }

 

4. 결과 확인

URL에 접속하여 정상적으로 적용되었는지 점검합니다.

ex)  https://본인의 사이트.com/robots.txt 또는 https://본인의 사이트.com/sitremap.txt

 

블로그 방문해주셔서 감사합니다 :)

잘 안되시거나 궁금한 점이 있으시다면, 댓글 남겨주세요

반응형
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.