1

I have a "drupal/legacy-project" Drupal 9 project (it was packed inside bought custom drupal theme and later updated to latest drupal 9 version) and I need some custom edits in my root .htaccess file. When I run "composer update" all my custom edits in .htacess are gone and my site is immediately broken. Composer output:

Scaffolding files for drupal/core:
- Copy [web-root]/.htaccess from assets/scaffold/files/htaccess

I want my root .htaccess updated with a core updates since there might be some security updates in the future. But also I want to keep my custom lines in the .htaccess. So I tried to implement file-mapping option in my composer.json:

"file-mapping": {
  "[web-root]/.htaccess": {
    "prepend": "assets/my_htaccess_additions.txt"
  }
}

But instead of prepending my custom lines from assets/my_htaccess_additions.txt file to root .htaccess I got no scaffolding at all and this text in my composer output:

Scaffolding files for drupal/core:
Skip [web-root]/.htaccess: overridden in drupal/legacy-project

Why is that and why composer mentions two projects (drupal/core and drupal/legacy-project) instead of one? Also I need to mention that this file-mapping setup works perfectly in my dev environment, but not in my prod environment

Thanks.

My system: ubuntu 18.04, php7.4, apache2. My composer.json contents:

{
"name": "drupal/legacy-project",
"description": "Project template for Drupal 9 projects with composer following drupal/drupal layout",
"type": "project",
"license": "GPL-2.0-or-later",
"homepage": "https://www.drupal.org/project/drupal",
"support": {
    "docs": "https://www.drupal.org/docs/user_guide/en/index.html",
    "chat": "https://www.drupal.org/node/314178"
},
"repositories": [
    {
        "type": "composer",
        "url": "https://packages.drupal.org/8"
    }
],
"require": {
    "composer/installers": "^1.9",
    "drupal/admin_toolbar": "^3.1",
    "drupal/better_exposed_filters": "^5.2",
    "drupal/block_visibility_groups": "^1.4",
    "drupal/color_field": "^2.5",
    "drupal/colorbox": "^1.10",
    "drupal/commerce": "^2.30",
    "drupal/commerce_currency_resolver": "^1.60",
    "drupal/commerce_shipping": "^2.4",
    "drupal/commerce_stock": "^1.0",
    "drupal/contact_block": "^1.6",
    "drupal/core-composer-scaffold": "^9.4",
    "drupal/core-project-message": "^9.4",
    "drupal/core-recommended": "^9.4",
    "drupal/core-vendor-hardening": "^9.4",
    "drupal/ctools": "^4.0",
    "drupal/entity_reference_facet_link": "^2.0",
    "drupal/facets": "^2.0",
    "drupal/facets_pretty_paths": "^1.2",
    "drupal/field_timer": "^1.2",
    "drupal/flag": "^4.0@beta",
    "drupal/fontawesome": "^2.23",
    "drupal/image_delta_formatter": "^1.1",
    "drupal/inline_entity_form": "^1.0@RC",
    "drupal/lang_dropdown": "^2.0",
    "drupal/pathauto": "^1.10",
    "drupal/redirect": "^1.7",
    "drupal/search_api": "^1.24",
    "drupal/simplenews": "^3.0@beta",
    "drupal/token": "^1.10",
    "drupal/video_embed_field": "^2.4",
    "drupal/votingapi": "^3.0@beta",
    "drupal/votingapi_widgets": "^1.0@alpha"
},
"conflict": {
    "drupal/drupal": "*"
},
"minimum-stability": "stable",
"prefer-stable": true,
"config": {
    "allow-plugins": {
        "composer/installers": true,
        "drupal/core-composer-scaffold": true,
        "drupal/core-project-message": true,
        "drupal/core-vendor-hardening": true,
        "dealerdirect/phpcodesniffer-composer-installer": true
    },
    "sort-packages": true
},
"extra": {
    "drupal-scaffold": {
        "locations": {
            "web-root": "./"
        },

    "file-mapping": {
    "[web-root]/.htaccess": {
      "prepend": "assets/my_htaccess_additions.txt"
    }
  }

    },
    "installer-paths": {
        "core": [
            "type:drupal-core"
        ],
        "libraries/{$name}": [
            "type:drupal-library"
        ],
        "modules/contrib/{$name}": [
            "type:drupal-module"
        ],
        "profiles/contrib/{$name}": [
            "type:drupal-profile"
        ],
        "themes/contrib/{$name}": [
            "type:drupal-theme"
        ],
        "drush/Commands/contrib/{$name}": [
            "type:drupal-drush"
        ],
        "modules/custom/{$name}": [
            "type:drupal-custom-module"
        ],
        "profiles/custom/{$name}": [
            "type:drupal-custom-profile"
        ],
        "themes/custom/{$name}": [
            "type:drupal-custom-theme"
        ]
    },
    "drupal-core-project-message": {
        "include-keys": [
            "homepage",
            "support"
        ],
        "post-create-project-cmd-message": [
            "<bg=blue;fg=white>                                                         </>",
            "<bg=blue;fg=white>  Congratulations, you’ve installed the Drupal codebase  </>",
            "<bg=blue;fg=white>  from the drupal/legacy-project template!               </>",
            "<bg=blue;fg=white>                                                         </>",
            "",
            "<bg=yellow;fg=black>Next steps</>:",
            "  * Install the site: https://www.drupal.org/docs/8/install",
            "  * Read the user guide: https://www.drupal.org/docs/user_guide/en/index.html",
            "  * Get support: https://www.drupal.org/support",
            "  * Get involved with the Drupal community:",
            "      https://www.drupal.org/getting-involved",
            "  * Remove the plugin that prints this message:",
            "      composer remove drupal/core-project-message"
        ]
    }
}

}

7
  • You win an unofficial community award for posting composer.json! Almost every question about Composer omits it. Take a bow. And IMO patching .htaccess is superior. I think the reason you see drupal/legacy-project in output is because that is the name value for your project, and you can configure that value any way you wish.
    – cilefen
    Sep 10, 2022 at 22:29
  • @cilefen haha, thanks, will learn patching, looks like I cannot fix that file-mapping feature.
    – loarrin
    Sep 10, 2022 at 22:50
  • 1
    Does this answer your question? How to patch your htaccess file correctly in composer.json
    – cilefen
    Sep 10, 2022 at 23:44
  • Yes, this is also documented in the README. Also, it looks like your project structure is a little unorthodox. It looks like you're not putting your web root in a subdirectory - normally the structure would have your composer.json at project root, alongside things like config and vendor, and then core, modules, themes, etc inside project_root/web.
    – sonfd
    Sep 10, 2022 at 23:50
  • @cilefen, to be precise it does not answer original question (about file-mapping), but looks like it can solve the issue another way, thank you.
    – loarrin
    Sep 11, 2022 at 17:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.