feat: add robots.txt and sitemap.xml routes for SEO optimization
- Implemented a new route for robots.txt to control crawler access. - Added a sitemap.xml route to provide search engines with a list of site URLs. - Included functions for URL normalization and XML escaping to ensure proper formatting.
This commit is contained in:
30
server/routes/robots.txt.js
Normal file
30
server/routes/robots.txt.js
Normal file
@@ -0,0 +1,30 @@
|
||||
function normalizeBaseUrl(value) {
|
||||
const raw = String(value || '').trim()
|
||||
if (!raw) return ''
|
||||
return raw.replace(/\/+$/, '')
|
||||
}
|
||||
|
||||
export default defineEventHandler((event) => {
|
||||
const runtimeConfig = useRuntimeConfig(event)
|
||||
const requestUrl = getRequestURL(event)
|
||||
|
||||
const baseUrl = normalizeBaseUrl(runtimeConfig.public?.baseUrl) || `${requestUrl.protocol}//${requestUrl.host}`
|
||||
|
||||
const lines = [
|
||||
'User-agent: *',
|
||||
'Allow: /',
|
||||
'Disallow: /cms',
|
||||
'Disallow: /cms/',
|
||||
'Disallow: /mitgliederbereich',
|
||||
'Disallow: /mitgliederbereich/',
|
||||
'Disallow: /api/',
|
||||
'Disallow: /login',
|
||||
'Disallow: /registrieren',
|
||||
'Disallow: /passwort-vergessen',
|
||||
'Disallow: /konto-loeschen',
|
||||
`Sitemap: ${baseUrl}/sitemap.xml`
|
||||
]
|
||||
|
||||
setHeader(event, 'Content-Type', 'text/plain; charset=utf-8')
|
||||
return `${lines.join('\n')}\n`
|
||||
})
|
||||
Reference in New Issue
Block a user