メインコンテンツまでスキップ

robots.txt

検索エンジンのクローラーへサイト内でアクセス可能な URL を知らせるために、appディレクトリのルートRobots Exclusion Standardへ準拠したrobots.txtファイルを追加または生成します。

静的なrobots.txt

app/robots.txt
User-Agent: *
Allow: /
Disallow: /private/

Sitemap: https://acme.com/sitemap.xml

Robots ファイルを生成する

Robots オブジェクトを返すrobots.jsまたはrobots.tsファイルを追加します。

app/robots.ts
import { MetadataRoute } from 'next'

export default function robots(): MetadataRoute.Robots {
return {
rules: {
userAgent: '*',
allow: '/',
disallow: '/private/',
},
sitemap: 'https://acme.com/sitemap.xml',
}
}

出力:

User-Agent: *
Allow: /
Disallow: /private/

Sitemap: https://acme.com/sitemap.xml

Robots オブジェクト

type Robots = {
rules:
| {
userAgent?: string | string[]
allow?: string | string[]
disallow?: string | string[]
crawlDelay?: number
}
| Array<{
userAgent: string | string[]
allow?: string | string[]
disallow?: string | string[]
crawlDelay?: number
}>
sitemap?: string | string[]
host?: string
}

バージョン履歴

VersionChanges
v13.3.0robots 導入