N
Nuxtβ€’5mo ago
Raiju

noindex a whole page directoru

is there a way to noindex a whole page directory in nuxt3? currently we are adding noindex to useHead on every page we dont want indexed page ---dir1 (we want to noindex this dir1 and all pages under it dir1/** ) ---dir2 ---dir3 dir3/page1 dir3/page2 how to achieve this? thanks
6 Replies
Cue
Cueβ€’5mo ago
Have you thought about combining routeRules with the X-Robots-Tag header? For example:
routeRules: {
'/dir1/**': { headers: { 'X-Robots-Tag': 'noindex, nofollow' } }
}
routeRules: {
'/dir1/**': { headers: { 'X-Robots-Tag': 'noindex, nofollow' } }
}
Or if you prefer the meta tags over headers, use a nitro plugin to hook into the rendering of the html:
export default defineNitroPlugin((nitroApp) => {
nitroApp.hooks.hook('render:html', (html, { event: { path } }) => {
if (path.startsWith('/dir1')) {
html.head.push('<meta name="robots" content="noindex, nofollow">')
}
})
})
export default defineNitroPlugin((nitroApp) => {
nitroApp.hooks.hook('render:html', (html, { event: { path } }) => {
if (path.startsWith('/dir1')) {
html.head.push('<meta name="robots" content="noindex, nofollow">')
}
})
})
Raiju
RaijuOPβ€’5mo ago
@cuebit thanks I will try both!
harlan
harlanβ€’5mo ago
just use robots.txt or nuxt/robots above solutions are just as good though
Raiju
RaijuOPβ€’5mo ago
@harlan I tried that but im having thse warning/errors regarding the runtime package
[11:49:05 PM] WARN "nitropack/runtime" is imported by "node_modules/@nuxtjs/robots/dist/runtime/nitro/composables/getPathRobotConfig.js", but could not be resolved – treating it as an external dependency.
[11:49:05 PM] WARN "nitropack/runtime" is imported by "node_modules/@nuxtjs/robots/dist/runtime/nitro/composables/getPathRobotConfig.js", but could not be resolved – treating it as an external dependency.
harlan
harlanβ€’5mo ago
πŸ€” which nuxt version out of interest?
Raiju
RaijuOPβ€’4mo ago
@harlan im running nuxt 3.10.3
Want results from more Discord servers?
Add your server