7

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?

15
 "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.

1

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)

  • This still won't work for certain elements of your .htaccess file because it pretty aggressively overwrites things such as BasePath which I need to be non-standard for a purpose I am using it for. – Patrick Dec 12 '19 at 22:25
  • @Patrick if you are talking about the RewriteBase, which is part of the htaccess file, you just need to put your change in the patch file. This is exactly how you implement changes in the htaccess file while letting the base file from being updated when needed. This is how we implement more than a hundred of new lines and changes on our own htaccess file. – Arakwar Dec 14 '19 at 3:23
  • Ahh, I get it now. I will try that soon. Thanks! – Patrick Dec 15 '19 at 5:40

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.