After running composer update my Drupal installation gets updated, but it also changes the content of the .htaccess file each time.

How can I correctly patch it?


In the scripts section of your composer.json file, use the following:

"post-drupal-scaffold-cmd": [
  "patch -p0 < patches/htaccess.patch"

(this requires "drupal-composer/drupal-scaffold" in your require section)

  • Using drupal-composer/drupal-project I simply added one function to its ScriptHandler.php that always symlinks me my own .htaccess from the composer root dir as post-install-cmd and post-update-cmd into the web root dir. – leymannx Oct 18 '18 at 12:52
  • 4
    @leymannx The problem with replacing it completely is that you won't get any changes that are done in core, the patch will keep them unless they conflict – Berdir Oct 18 '18 at 14:57
  • And core .htacess changes are often (not always of course) security related, so it’s important to merge rather than overwrite changes – Clive Oct 18 '18 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.