I am using composer with Drupal lightning. If I update Drupal via composer, it updates the .htaccess file.

Is there any way to prevent the .htaccess file from being overwritten?

 "extra": {
   "drupal-scaffold": { 
       "source": "http://cgit.drupalcode.org/drupal/plain/{path}?h={version}", 
       "excludes": [ ".htaccess", "robots.txt" ]

Put this above code in your composer.json file.

  • Worked like a charm! – albertski Dec 22 '16 at 15:24

While the accepted answer is correct and this prevent the .htacces file from being overwritten, most updates done to that files are linked to security issues. You should patch the file instead, as described in this answer : https://drupal.stackexchange.com/a/271147/25673

Here's a copy of the answer by Stef Van Looveren

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)

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.