Skip to content
LightNet v4 is here! Learn how to upgrade your site

Configure search engines

LightNet allows search engines, such as Google, to index your site by default. You can ask them to exclude your whole site or individual pages from search results.

The disallowSearchIndexing setting controls whether generated HTML pages ask search engines to exclude them from search results. It defaults to false, which allows indexing. Set disallowSearchIndexing to true to ask search engines not to index your site or a page. LightNet adds this robots meta tag to the <head> of the affected HTML pages:

<meta name="robots" content="noindex">

See also Block Search Indexing with noindex in Google Search Central.

Set disallowSearchIndexing to true in your LightNet configuration:

astro.config.mjs
import lightnet from "lightnet";
import { defineConfig } from "astro/config";
export default defineConfig({
integrations: [
lightnet({
disallowSearchIndexing: true,
// ...
}),
],
});

When you run pnpm build with this site-wide setting, LightNet:

  • Adds the noindex meta tag to generated HTML pages.
  • Omits canonical and sitemap links from those pages.
  • Does not generate its own robots.txt or automatically configure sitemap generation.

Page-level settings can override the HTML indexing and link behavior, as described below. A custom robots.txt is preserved, and any separately configured @astrojs/sitemap integration is managed independently. For crawling requirements, see Remove blocking robots.txt rules.

For a Markdown page, set disallowSearchIndexing in the frontmatter:

src/pages/en/about.md
---
layout: "lightnet/layouts/MarkdownPage.astro"
disallowSearchIndexing: true
---
# About
About this site.

For a page built with the Page component, pass disallowSearchIndexing directly:

---
import { Page } from "lightnet/components";
---
<Page disallowSearchIndexing>
<h1>Public page</h1>
</Page>

The page-level value takes precedence over the site configuration. To allow indexing for a page when the whole site uses noindex, use disallowSearchIndexing: false in its frontmatter or <Page disallowSearchIndexing={false}> in its component.

LightNet does not support requesting noindex for individual media items.

The disallowSearchIndexing setting affects generated HTML pages; it does not add this header to other files served through your site. To ask search engines not to index files such as PDFs, add an X-Robots-Tag: noindex HTTP response header to the files.

If the domain or subdomain serving your files is proxied through Cloudflare, you can add the header using a Response Header Transform Rule. For example, to apply noindex to PDF files:

  1. Open the Cloudflare dashboard and select the domain serving your files.

  2. Go to Rules > Overview > Create rule > Response Header Transform Rule.

  3. Enter a descriptive rule name, such as “Do not index PDFs”.

  4. Under When incoming requests match, select Custom filter expression and configure:

    Field Operator Value
    URI Path (http.request.uri.path) ends with .pdf
  5. Under Modify response header, configure:

    Operation Header name Value
    Set static X-Robots-Tag noindex
  6. Select Deploy to activate the rule.

  7. Open your browser’s developer tools and select the Network tab. Open or reload a PDF URL from your site, select the PDF request, and inspect its response headers. You should see X-Robots-Tag: noindex.

This rule matches URL paths ending in lowercase .pdf. Adjust the condition if your files use other extensions or paths. For crawling requirements, see Remove blocking robots.txt rules.

See Cloudflare’s response header transform rule instructions and Google’s documentation for the X-Robots-Tag header.

Use disallowSearchIndexing to hide pages from search engines, and remove any robots.txt rules that block search engines from crawling those pages. If your existing public/robots.txt only contains rules intended to prevent indexing, remove the file and use disallowSearchIndexing instead.

A robots.txt rule like Disallow: / blocks search engines from crawling your site. If a search engine cannot crawl generated HTML, it cannot see the noindex directive. As a result, the page may still appear in search results if the search engine already knows about it from before or finds links to it elsewhere.

See also Understand the limitations of a robots.txt file in Google Search Central.

For most sites, leave disallowSearchIndexing unset or set it to false in your LightNet configuration in astro.config.mjs so people can find your content through search engines. When you run pnpm build with this setting, LightNet:

  • Allows indexing of generated HTML pages and adds canonical and sitemap links, unless a page overrides the setting.
  • Generates robots.txt with Allow: / and a Sitemap: line pointing to the sitemap index, unless you provide a custom file.
  • Automatically configures sitemap generation to produce sitemap-index.xml and sitemap files, unless you have already configured @astrojs/sitemap separately.
  • Links translations of a media item, which are media items with the same commonId, so search engines can show people the version in their language.

These files help search engines discover and crawl your content:

  • A sitemap lists page URLs, helping search engines find pages without relying only on links from other pages or sites. This is especially useful for a large media library or newly added content.
  • A robots.txt file provides instructions about which parts of the site search engines can crawl. It can also tell search engines where to find a sitemap.

For most sites, we recommend letting LightNet generate robots.txt instead of maintaining a custom file.

For more background, see Google’s sitemap overview and introduction to robots.txt.

Sitemaps and crawling instructions help search engines find your content, but do not guarantee inclusion in search results or a particular ranking.

Maintain a custom public/robots.txt only if you need specific crawling rules, such as asking crawlers to avoid a particular URL path. When you run pnpm build, LightNet preserves this file and skips automatic robots.txt generation, even when disallowSearchIndexing is true. LightNet does not add or update rules or the sitemap reference in your custom file.

Include a Sitemap: line pointing to the full URL of your site’s sitemap index:

public/robots.txt
User-agent: *
Allow: /
Sitemap: https://example.com/sitemap-index.xml

Replace https://example.com/ with your site’s URL, including any base path. Adjust the crawling rules for your needs, but allow search engines to crawl pages that use noindex so they can read that directive.