Search by

abdur-rahaman / index-now

abdurrahamanbabu

A lightweight Laravel package for seamless IndexNow API integration, enabling automatic URL submission to supported search engines whenever your website content is published, updated, or deleted.

v1.0.0 2026-11-29 06:33 UTC

This package is auto-updated.

Last update: 2026-11-29 18:55:00 UTC


README

Latest Version on Packagist Total Downloads License

A lightweight, developer-friendly Laravel package for seamless IndexNow API integration. Automatically notify supported search engines (Bing, Yandex, Seznam.cz, Naver, and others) when website URLs are published, updated, or deleted — helping them discover content changes faster.

Features

  • Simple facade API: IndexNow::addUrl([...])
  • Single URL and bulk URL submission (up to 10,000 URLs per request, with automatic batching)
  • URL validation and host matching
  • Automatic duplicate removal
  • Optional key location support
  • Structured responses with clear success/failure helpers
  • Configurable timeouts, SSL verification, and exception behaviour
  • Artisan commands for key generation and bulk submission from a file
  • Laravel auto-discovery, facade, and dependency injection
  • Fully tested with Orchestra Testbench and HTTP fakes

Requirements

  • PHP 8.1+ (PHP 8.3+ required for Laravel 13)
  • Laravel 10.x, 11.x, 12.x, or 13.x

Installation

composer require abdur-rahaman/index-now

Laravel will auto-discover the service provider and facade.

Publish the configuration (optional)

php artisan vendor:publish --tag=index-now-config

This creates config/index-now.php.

Configuration

Add the following to your .env file:

APP_INDEXNOW_API_KEY="your-secret-api-key"
APP_INDEXNOW_HOST="abdurrahaman.com"
Variable Description Default
APP_INDEXNOW_API_KEY Your IndexNow API key ''
APP_INDEXNOW_HOST Your site hostname (no protocol) ''
APP_INDEXNOW_ENDPOINT API endpoint https://api.indexnow.org/indexnow
APP_INDEXNOW_KEY_LOCATION Optional absolute URL of the key file null
APP_INDEXNOW_TIMEOUT Request timeout (seconds) 10
APP_INDEXNOW_CONNECT_TIMEOUT Connection timeout (seconds) 5
APP_INDEXNOW_VERIFY_SSL Verify SSL certificates true
APP_INDEXNOW_THROW Throw exceptions instead of returning failure responses false

Generate an API key and verification file

php artisan index-now:generate-key

This command will:

  1. Use the key already set in APP_INDEXNOW_API_KEY, or generate a new secure key and print it so you can add it to .env.
  2. Create public/{API_KEY}.txt containing the key.

The file must be publicly reachable, for example:

https://abdurrahaman.com/your-api-key.txt

Search engines use this file to verify ownership of the host.

Important: Never commit your real API key or expose it in logs. The package intentionally avoids logging the key.

Basic Usage

use AbdurRahaman\IndexNow\Facades\IndexNow;

// Single URL (string)
$result = IndexNow::addUrl(
    route('blog.show', ['slug' => $blog->slug])
);

// Multiple URLs
$result = IndexNow::addUrl([
    'https://abdurrahaman.com/blog/post-one',
    'https://abdurrahaman.com/blog/post-two',
]);

if ($result->successful()) {
    // Submission accepted by the IndexNow endpoint
}

if ($result->failed()) {
    // Inspect $result->message() and $result->errors()
}

Notify about updates or deletions

IndexNow uses the same notification protocol for publish, update, and delete. The package provides semantic methods for clarity:

IndexNow::updateUrl([
    route('blog.show', ['slug' => $blog->slug]),
]);

IndexNow::removeUrl([
    route('blog.show', ['slug' => $blog->slug]),
]);

Dependency injection

use AbdurRahaman\IndexNow\IndexNowManager;

public function publish(IndexNowManager $indexNow)
{
    return $indexNow->addUrl([
        route('blog.show', ['slug' => 'example']),
    ]);
}

Response Handling

Every submission method returns an IndexNowResponse instance:

$result = IndexNow::addUrl(['https://abdurrahaman.com/page']);

$result->successful();   // bool
$result->failed();       // bool
$result->status();       // int (HTTP status or 0 on connection error)
$result->message();      // Human-readable message
$result->submittedUrls(); // array of URLs that were sent
$result->errors();       // array of error messages
$result->batches();      // array of IndexNowResponse (for bulk > 10k)
$result->toArray();      // array representation
$result->toJson();       // JSON string

HTTP status meanings

Status Meaning
200 URLs submitted successfully
202 URLs received; key validation pending
400 Invalid request
403 Key validation failed
422 URL does not belong to the host
429 Too many requests

A successful API response does not guarantee that search engines will index the URL. It only confirms that the notification was accepted.

Bulk Submission

You can submit up to 10,000 URLs in a single request. If you supply more, the package automatically splits them into batches and returns an aggregated result:

$urls = [/* thousands of URLs */];

$result = IndexNow::addUrl($urls);

if ($result->successful()) {
    // All batches succeeded
}

foreach ($result->batches() as $batch) {
    // Inspect each batch response
}

Submit URLs from a File

Create a text file with one URL per line (lines starting with # are ignored):

https://abdurrahaman.com/page-one
https://abdurrahaman.com/page-two
# this is a comment
https://abdurrahaman.com/page-three

Then run:

php artisan index-now:submit path/to/urls.txt
php artisan index-now:submit path/to/urls.txt --action=update
php artisan index-now:submit path/to/urls.txt --action=remove

Exception Handling

By default (throw => false), configuration and validation errors are returned as failed IndexNowResponse objects.

To throw exceptions instead:

APP_INDEXNOW_THROW=true

Or in config:

'throw' => true,

Available exception classes:

  • AbdurRahaman\IndexNow\Exceptions\ConfigurationException
  • AbdurRahaman\IndexNow\Exceptions\InvalidUrlException
  • AbdurRahaman\IndexNow\Exceptions\ApiException
  • AbdurRahaman\IndexNow\Exceptions\IndexNowException (base)

Artisan Commands

Command Description
php artisan vendor:publish --tag=index-now-config Publish the configuration file
php artisan index-now:generate-key Generate API key and public verification file
php artisan index-now:generate-key --force Overwrite an existing verification file
php artisan index-now:submit urls.txt Submit URLs from a file
php artisan index-now:submit urls.txt --action=update Submit as update notifications

Testing

composer install
composer test

Tests use Orchestra Testbench and Laravel’s HTTP fake — no real external requests are made.

Troubleshooting

403 Key validation failed

  • Ensure public/{API_KEY}.txt exists and contains exactly the API key.
  • Confirm the file is publicly accessible over HTTPS.
  • Clear any CDN/cache in front of the key file.

422 URL does not belong to the host

  • Check that APP_INDEXNOW_HOST matches the host of the URLs you submit (protocol and www are normalized).

Connection / timeout errors

  • Increase timeout / connect_timeout in the config.
  • Verify outbound HTTPS access from your server to api.indexnow.org.

Missing configuration

  • Set both APP_INDEXNOW_API_KEY and APP_INDEXNOW_HOST in .env.
  • Run php artisan config:clear after changing environment variables.

Contributing

Please see CONTRIBUTING.md for details.

Changelog

Please see CHANGELOG.md for recent changes.

License

This package is open-sourced software licensed under the MIT license.

Author

Abdur Rahaman

Made with care for the Laravel community.