robots.txt
在 app
目錄的根目錄下新增或生成符合 Robots 排除標準的 robots.txt
檔案,用於告知搜尋引擎爬蟲程式可以存取您網站上的哪些 URL。
靜態 robots.txt
User-Agent: *
Allow: /
Disallow: /private/
Sitemap: https://acme.com/sitemap.xml
生成 Robots 檔案
新增一個 robots.js
或 robots.ts
檔案,並回傳一個 Robots
物件。
import { MetadataRoute } from 'next'
export default function robots(): MetadataRoute.Robots {
return {
rules: {
userAgent: '*',
allow: '/',
disallow: '/private/',
},
sitemap: 'https://acme.com/sitemap.xml',
}
}
export default function 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
}
版本歷史
版本 | 變更內容 |
---|---|
v13.3.0 | 新增 robots 功能。 |