@@ -8,8 +8,9 @@ import { createNitroRouteRuleMatcher } from '../kit'
88import { getSiteRobotConfig } from './getSiteRobotConfig'
99
1010export function getPathRobotConfig ( e : H3Event , options ?: { userAgent ?: string , skipSiteIndexable ?: boolean , path ?: string } ) : RobotsContext {
11+ const runtimeConfig = useRuntimeConfig ( e )
1112 // has already been resolved
12- const { robotsDisabledValue, robotsEnabledValue, isNuxtContentV2 } = useRuntimeConfig ( ) [ 'nuxt-robots' ]
13+ const { robotsDisabledValue, robotsEnabledValue, isNuxtContentV2 } = runtimeConfig [ 'nuxt-robots' ]
1314 if ( ! options ?. skipSiteIndexable ) {
1415 if ( ! getSiteRobotConfig ( e ) . indexable ) {
1516 return {
@@ -85,7 +86,16 @@ export function getPathRobotConfig(e: H3Event, options?: { userAgent?: string, s
8586
8687 // 3. nitro route rules
8788 nitroApp . _robotsRuleMactcher = nitroApp . _robotsRuleMactcher || createNitroRouteRuleMatcher ( )
88- const routeRules = normaliseRobotsRouteRule ( nitroApp . _robotsRuleMactcher ( path ) )
89+ let routeRulesPath = path
90+ // if we're using i18n we need to strip leading prefixes so the rule will match
91+ if ( runtimeConfig . public ?. i18n ?. locales ) {
92+ const { locales } = runtimeConfig . public . i18n
93+ const locale = locales . find ( l => routeRulesPath . startsWith ( `/${ l . code } ` ) )
94+ if ( locale ) {
95+ routeRulesPath = routeRulesPath . replace ( `/${ locale . code } ` , '' )
96+ }
97+ }
98+ const routeRules = normaliseRobotsRouteRule ( nitroApp . _robotsRuleMactcher ( routeRulesPath ) )
8999 if ( routeRules && ( typeof routeRules . allow !== 'undefined' || typeof routeRules . rule !== 'undefined' ) ) {
90100 return {
91101 indexable : routeRules . allow ,
0 commit comments