728x90
반응형
Sitemap.xml은 웹사이트의 페이지 구조를 검색 엔진에 알리기 위해 사용되는 XML 파일입니다.
이는 검색 엔진이 웹사이트를 효율적으로 크롤링하고 색인(Indexing)할 수 있도록 돕습니다.
아래는 sitemap.xml을 만드는 방법과 이를 활용하는 방법입니다.
Sitemap.xml 작성법
Sitemap.xml 파일은 특정 XML 형식에 따라 작성됩니다. 기본 형식은 다음과 같습니다:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://www.example.com/</loc>
<lastmod>2025-02-10</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>https://www.example.com/about</loc>
<lastmod>2025-02-05</lastmod>
<changefreq>monthly</changefreq>
<priority>0.8</priority>
</url>
</urlset>
태그 설명
- <loc>
- URL을 지정합니다.
- 예: https://www.example.com/
- <lastmod>
- 페이지가 마지막으로 수정된 날짜를 나타냅니다. (형식: YYYY-MM-DD)
- 예: <lastmod>2025-02-10</lastmod>
- <changefreq>
- 페이지가 얼마나 자주 변경되는지 나타냅니다.
- 값: always, hourly, daily, weekly, monthly, yearly, never
- 예: <changefreq>daily</changefreq>
- <priority>
- 페이지의 중요도를 나타냅니다. (범위: 0.0 ~ 1.0)
- 예: <priority>1.0</priority>
Sitemap.xml 생성 방법
1. 수동 작성
- 텍스트 편집기(예: Notepad++, VS Code)를 열고 XML 형식으로 직접 작성합니다.
- 작성 후 sitemap.xml 파일로 저장합니다.
2. 자동 생성 도구 사용
- 온라인 도구
- XML Sitemap Generator
URL을 입력하면 자동으로 sitemap 파일을 생성해 줍니다.
- XML Sitemap Generator
- CMS 플러그인
- WordPress:
- 플러그인: Yoast SEO, Rank Math
- 설치 후 플러그인 설정에서 자동으로 Sitemap.xml 생성 가능.
- Shopify, Wix: Sitemap은 기본적으로 자동 생성됩니다.
- WordPress:
3. 프로그램으로 생성 (Python 예제)
Python을 사용하여 자동으로 sitemap.xml을 생성할 수 있습니다:
from datetime import datetime
urls = [
{"loc": "https://www.example.com/", "lastmod": "2025-02-10", "changefreq": "daily", "priority": 1.0},
{"loc": "https://www.example.com/about", "lastmod": "2025-02-05", "changefreq": "monthly", "priority": 0.8},
]
sitemap_content = '<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n'
for url in urls:
sitemap_content += f" <url>\n"
sitemap_content += f" <loc>{url['loc']}</loc>\n"
sitemap_content += f" <lastmod>{url['lastmod']}</lastmod>\n"
sitemap_content += f" <changefreq>{url['changefreq']}</changefreq>\n"
sitemap_content += f" <priority>{url['priority']}</priority>\n"
sitemap_content += f" </url>\n"
sitemap_content += "</urlset>"
# Save to a file
with open("sitemap.xml", "w") as file:
file.write(sitemap_content)
print("Sitemap generated successfully!")
4. 프레임워크 별 생성
- Django
- Django에서 django.contrib.sitemaps 모듈을 사용해 sitemap 생성 가능.
- Ruby on Rails
- sitemap_generator Gem 사용.
Sitemap.xml 서버에 업로드
- 파일 업로드
- 작성된 sitemap.xml 파일을 웹 서버의 루트 디렉터리에 업로드합니다.
예: https://www.example.com/sitemap.xml
- 작성된 sitemap.xml 파일을 웹 서버의 루트 디렉터리에 업로드합니다.
- robots.txt에 추가
검색 엔진이 Sitemap을 찾을 수 있도록 robots.txt에 경로를 추가합니다.
User-agent: *
Sitemap: https://www.example.com/sitemap.xml
3.Google Search Console 제출
- Google Search Console에 접속.
- "Sitemaps" 섹션에서 Sitemap URL을 제출.
Sitemap 작성 시 유의점
- 최대 URL 개수: 한 파일에 최대 50,000개의 URL을 포함할 수 있습니다. 초과 시 분할 작성 필요.
- 파일 크기 제한: 50MB를 초과하면 분할 작성. (gzip 압축 사용 가능)
- 정확한 URL 사용: 모든 URL은 절대 경로로 작성. (https:// 포함)
- 주기적 업데이트: 사이트 변경 시 sitemap도 최신 상태로 유지.
Sitemap.xml은 검색 엔진이 사이트를 더 잘 이해하고 색인화하도록 도와주는 중요한 파일입니다. 올바르게 생성하고 제출하면 SEO에 긍정적인 영향을 미칩니다! 😊
728x90
반응형
'IT지식' 카테고리의 다른 글
[php] index.php (0) | 2025.02.07 |
---|---|
sitemap.xml 파일 위치 (0) | 2025.02.05 |
301 redirection (0) | 2025.02.02 |
canonical URL (0) | 2025.02.01 |
SEO란? (0) | 2025.01.31 |