Provide an example of how to manage robots.txt and .htaccess with Composer

Created on 18 November 2019, about 5 years ago
Updated 22 April 2024, 8 months ago

Problem/Motivation

Users are encouraged to modify their .htaccess file directly in a comment in that same file; since this comment has been in place for a while, people are used to doing it. Unfortunately, this sort of modification is erased during Drupal updates (e.g. when running drupal pm-update), and with the introduction of the Drupal Composer Scaffold tool, composer install also puts these files in danger of being overwritten. See 🐛 Avoid overwriting .htaccess changes during scaffolding > security problem Needs work for some of the implications of this.

It would be desirable if we could start guiding users towards a more modern, Composer-based way to manage their .htaccess and robots.txt customizations. The Drupal Composer Scaffold tool provides patching and append/prepend features to make these changes easier to maintain, for example.

Proposed resolution

Add two examples to drupal/recommended-project:

  1. Prepend to robots.txt
  2. Patch .htaccess

These examples should not be added to the legacy project for now, as that is used to generate downloaded tarballs.

Remaining tasks

The scaffold files in drupal/core should say "do not modify these files", rather than the patch file / prepend file in the template.

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

tbd

📌 Task
Status

Needs work

Version

11.0 🔥

Component
Composer 

Last updated 3 days ago

No maintainer
Created by

🇺🇸United States greg.1.anderson

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • Status changed to Needs review 9 months ago
  • 🇮🇳India bhanu951

    Rerolled patch 3095214-16.patch against 11.x branch and updated web-root directory to web in all places instead of mixed docroot and web , updated patch generation git command to include --no-prefix

  • Status changed to Needs work 9 months ago
  • The Needs Review Queue Bot tested this issue.

    While you are making the above changes, we recommend that you convert this patch to a merge request . Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)

  • Pipeline finished with Failed
    9 months ago
    Total: 574s
    #118268
  • Status changed to Needs review 9 months ago
  • 🇮🇳India bhanu951

    Tests failed due to missing patch utility in the docker image. Hence setting to NR again.

    git check-ignore 'vendor'
    > post-drupal-scaffold-cmd: cd web && patch -p1 <
    ../scaffold-modifications/htaccess.patch
    Executing command (CWD): cd web && patch -p1 <
    ../scaffold-modifications/htaccess.patch
    sh: 1: patch: not found
    Script cd web && patch -p1 < ../scaffold-modifications/htaccess.patch
    handling the post-drupal-scaffold-cmd event returned with error code 127
    Failed asserting that 127 matches expected 0.
    
  • Pipeline finished with Failed
    9 months ago
    Total: 37s
    #118800
  • Pipeline finished with Failed
    9 months ago
    Total: 37s
    #118808
  • Pipeline finished with Failed
    9 months ago
    Total: 487s
    #118887
  • Status changed to Postponed 9 months ago
  • Pipeline finished with Canceled
    9 months ago
    Total: 384s
    #123957
  • Pipeline finished with Failed
    9 months ago
    Total: 606s
    #123965
  • Pipeline finished with Failed
    9 months ago
    Total: 559s
    #124065
  • Status changed to Needs work 8 months ago
  • Pipeline finished with Canceled
    8 months ago
    Total: 57s
    #154344
  • Pipeline finished with Failed
    8 months ago
    Total: 620s
    #154345
  • Pipeline finished with Failed
    8 months ago
    Total: 961s
    #154362
Production build 0.71.5 2024