Skip to content

Conversation

@brunoamui
Copy link
Collaborator

Summary

This PR adds environment-controlled SEO indexing functionality to prevent search engines from indexing development and staging environments while allowing indexing in production.

Changes

Core Implementation

  • SEO Control Component: Conditionally adds noindex meta tags based on environment variables
  • Dynamic robots.txt: Environment-controlled robots.txt endpoint that blocks crawlers when indexing is disabled
  • Environment Configuration: New environment variables for controlling indexing behavior

Files Added/Modified

  • components/seo-control.tsx - New component for meta tag management
  • pages/robots.txt.tsx - Dynamic robots.txt endpoint
  • pages/_app.tsx - Integration of SEO control component
  • next.config.js - Environment variable configuration
  • .env.local - Local development settings (indexing disabled)
  • .env.local.example - Example environment configuration
  • docs/seo-indexing-control.md - Comprehensive documentation

Environment Variables

  • NEXT_PUBLIC_ALLOW_INDEXING: Controls whether search engines can index the site (true/false)
  • NEXT_PUBLIC_SITE_URL: Site URL for sitemap reference in robots.txt

Behavior

When NEXT_PUBLIC_ALLOW_INDEXING=false (Development/Staging)

  • Adds <meta name="robots" content="noindex, nofollow" /> to all pages
  • Adds <meta name="googlebot" content="nosnippet" /> for extra protection
  • robots.txt returns Disallow: / blocking all crawlers

When NEXT_PUBLIC_ALLOW_INDEXING=true (Production)

  • No noindex meta tags are added
  • robots.txt allows all crawlers and includes sitemap reference

Testing

✅ Verified meta tags are correctly added in development
✅ Verified robots.txt responds appropriately to environment settings
✅ Confirmed environment variable control works as expected

Documentation

Added comprehensive documentation in docs/seo-indexing-control.md covering:

  • Feature overview and implementation details
  • Environment variable configuration
  • Testing instructions
  • Deployment considerations

Production Deployment

For production deployment, ensure NEXT_PUBLIC_ALLOW_INDEXING=true is set to allow search engine indexing.

- add SEOControl component for conditional robots meta tags
- create dynamic robots.txt based on NEXT_PUBLIC_ALLOW_INDEXING
- update next.config.js with new environment variables
- include comprehensive documentation and examples
- support for staging/production environment differentiation
- compatible with Google AI Mode and modern SEO practices

Environment variables:
- NEXT_PUBLIC_ALLOW_INDEXING: controls indexing (default: true)
- NEXT_PUBLIC_SITE_URL: site URL for robots.txt sitemap reference
@netlify
Copy link

netlify bot commented Jul 28, 2025

Deploy Preview for leafy-mooncake-7c2e5e ready!

Name Link
🔨 Latest commit 63de381
🔍 Latest deploy log https://app.netlify.com/projects/leafy-mooncake-7c2e5e/deploys/6887dc9a3e0f4d0008feb1ac
😎 Deploy Preview https://deploy-preview-257--leafy-mooncake-7c2e5e.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request does not contain a valid label. Please add one of the following labels: ['release-no', 'release-auto', 'release-patch', 'release-minor', 'release-major']

@brunoamui brunoamui requested a review from Copilot July 28, 2025 20:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements environment-controlled SEO indexing to prevent search engines from indexing non-production environments while allowing indexing in production through environment variable configuration.

  • Adds conditional noindex meta tags based on NEXT_PUBLIC_ALLOW_INDEXING environment variable
  • Implements dynamic robots.txt generation that blocks or allows crawlers depending on environment
  • Integrates SEO control component globally through _app.tsx

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/components/seo-control.tsx New component that conditionally adds noindex meta tags when indexing is disabled
src/pages/robots.txt.tsx Dynamic robots.txt endpoint that generates appropriate crawler directives based on environment
src/pages/_app.tsx Integrates SEO control component globally across all pages
docs/seo-indexing-control.md Comprehensive documentation covering implementation, configuration, and usage
.env.local.example Example environment configuration file with SEO indexing variables

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant