composer – What is the proper process to customize htaccess files?

Depending on level of customization, there are two strategies you could employ.

  • Patch drupal/core with a modified htaccess file including your customization.
  • Override the htaccess file via scaffolding.

If you choose the first option here is a really easy way to do it.

  1. Checkout the version of Drupal you are using to a folder.
  2. Adjust the htaccess file in assets/scaffold.
  3. Run git diff > htaccess.patch.
  4. Go back to your project and create a patches folder, place the new file inside.
  5. Add the following to composer.json extra section (make sure you have installed cweagans/composer-patches):
"patches": {
  "drupal/core": {
    "Add redirects": "patches/htaccess.patch"

If you choose option two:

  1. Create an assets/scaffold folder(s) in your project.
  2. Copy the htaccess file inside of it.
  3. Make your adjustments to the file.
  4. Add the following to composer.json extra section:
"drupal-scaffold": {
  "locations": {
    "web-root": "web/"
  "file-mapping": {
    "(web-root)/.htaccess": "assets/scaffold/.htaccess"