Problem/Motivation

Drupal Core provides a robots.txt file that dissalows /search/.
Please note the trailing slash in that entry.
Link to source: https://git.drupalcode.org/project/drupal/-/blob/11.x/robots.txt?ref_typ...

Drupal sites often don't rely in core search but in custom views with filters or search_api views and facets.
Most of the times these use http query arguments, in the form of /search?title=robots.
Please note the absence of a trailing slash, the word search is followed by the arguments (?)

The current Drupal Core robots.txt rules do not apply for /search?

This creates a scenario where bots/crawlers, bad or legitimate like Googlebot and Bingbot will start indexing all search pages, creating a bad index and, in the case of facets, also causing server performance issues as they try to follow any possible combination of faceted search pages.

Steps to reproduce

- Install Drupal
- Create a search_api faceted search
- Submit site to google
- See crawl logs and see googlebot index faceted pages
- See it trying every possible combination, an endless situation

Proposed resolution

All of this can be easily fixed for all sites by changing:
Disallow: /search/
to

Disallow: /search/
Disallow: /search?

See https://developers.google.com/search/docs/crawling-indexing/robots/robot... for details and info on what led to this suggestion.

Remaining tasks

Fix the line in robots.txt, both in drupal root and scaffold files folder.

Release notes snippet

The default robots.txt file now blocks search result pages with query parameters from being crawled by search engines. Previously, only path-based search URLs (like /search/keyword) were blocked, but query parameter searches (like /search?q=keyword) remained accessible to crawlers. This caused search engines to index dynamically generated search results and crawl infinite combinations of faceted search pages, degrading site performance and SEO quality.

Site owners who have customized their robots.txt file should consider manually adding these rules:

Disallow: /search?
Disallow: /index.php/search?

This change only affects new installations and sites using the default scaffold robots.txt. Existing custom robots.txt files will not be automatically updated. See the change record (draft, not published) for more information.

Issue fork drupal-3550083

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

bserem created an issue. See original summary.

bserem’s picture

Status: Active » Needs review
bserem’s picture

Issue summary: View changes

bserem changed the visibility of the branch 3550083- to hidden.

smustgrave’s picture

Version: 11.2.x-dev » 11.x-dev
Status: Needs review » Needs work

MRs should point to 11.x and should be one MR please.

May want to add an additional entry but not sure we should remove the existing. Temped to tag for framework manager sign off.

markconroy’s picture

Thanks for working on this @bserem. I've seen a lot of LocalGov Drupal sites getting hammered because of crawlers following all facets pages.

I think this issue/MR would definitely qualify as a "Needs framework manager signoff" issue.

bserem changed the visibility of the branch 3550083-robotstxt-search-d10 to hidden.

bserem’s picture

Status: Needs work » Needs review

Thanks for the pointers @smustgrave

  • Updated the target branch
  • Hid the MR towards Drupal 10
  • I am not allowed to delete my branches from gitlab

Having an extra entry is also an option, I opted against it for less repetition, as the current change achieves the same results.

Putting back to needs review.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

bserem’s picture

Status: Needs work » Needs review

Recreated the branch and the MR to not include any 11.2.x stuff as advised in #7 above.

The diff is now clean. Marking as needs review again.

smustgrave’s picture

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

nod_’s picture

Status: Needs work » Needs review
bserem’s picture

Issue summary: View changes
ifrik’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Vienna2025

This works, and it solves the issue. Core's search pages use the path /search/node and /search/user so the trailing / make sense, but other search pages (for example when building a search view using Search API) often just use /search.
Since the core search paths are still covered by this change, it's a simple change that will benefit other setups as well.

poker10’s picture

Status: Reviewed & tested by the community » Needs work

Thanks for working on this.

I think that the proposed change can cause issues on some sites. As per https://developers.google.com/search/docs/crawling-indexing/robots/robot... , the Disallow: /search will match anything starting with /search, so it has a potential to also block any content with URL alias starting with that string (for example a news with an alias of /search-for-donations, etc.). Based on this, moving back to NW.

Also this is probably more like a Feature request than a Bug, given there is no issue with the core itself.

bserem’s picture

Assigned: Unassigned » bserem
bserem’s picture

Status: Needs work » Needs review
bserem’s picture

Assigned: bserem » Unassigned
bserem’s picture

I've only now realized that comments submitted in gitlab might not be visible here according to user settings. Work has been done in https://git.drupalcode.org/project/drupal/-/merge_requests/13399#note_60... and screenshots have been added in that comment to visualize the changes.

Quoting gitlab comment here, without screenshots, for clarity:

Thanks @poker10 for the review. Your concern is valid, so I updated the robots.txt file to disallow /search/ (as it was) and /search? (new entry).

bserem’s picture

Title: robots.txt should disallow all '/search*' pages by default » robots.txt should disallow all '/search/' and '/search?' pages by default
Issue summary: View changes
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Believe feedback has been addressed.

catch’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record, +Needs release note

This is a good idea but it needs a change record and release notes snippet since it's changing site owner managed/scaffolded files.

bserem’s picture

Issue summary: View changes
Status: Needs work » Reviewed & tested by the community

Made a change record: https://www.drupal.org/node/3567198
Added "Release notes snippet".

Full transparency: as English is not my first language I did use an LLM to improve my writing to something more formal.

Moving this back to RTBC, I hope I this is the right place.

bserem’s picture

Cleaning up tags.

I also feel "needs framework manager review" can go since @smustgrave and @catch have checked this.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new768 bytes

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

smustgrave’s picture

Status: Needs work » Reviewed & tested by the community

Bot rebellion

longwave made their first commit to this issue’s fork.

  • godotislate committed a38ee74e on main
    feat: #3550083 robots.txt should disallow all '/search/' and '/search?'...

  • godotislate committed 519d5d64 on 11.x
    feat: #3550083 robots.txt should disallow all '/search/' and '/search?'...
godotislate’s picture

Version: main » 11.x-dev
Category: Bug report » Feature request
Status: Reviewed & tested by the community » Fixed
Issue tags: -Needs framework manager review

Removed the "Needs framework manager review" tag since @catch approved in #25.

Committed a38ee74 and pushed to main and committed 519d5d6 and pushed to 11.x. Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

longwave’s picture

Changes to user managed files should be called out in the release notes.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.