4

When updating Magento 2 via Composer, the .htaccess file in the Magento root directory gets overwritten with the default repository version. Therefore losing my customisations, which I have to go in and replace each time.

Is there a way that I can have Composer skip this file by editing the composer.json or something like that?

3
  • I don't think this is possible. The rule comes from the magento2-base package composer.json. If changes occur there, you want your file to be updated. By excluding it you'd have to apply any changes manually anyway after each update ..
    – tecjam
    Commented May 17, 2019 at 10:09
  • That's a bit annoying. Thanks
    – Craig
    Commented May 17, 2019 at 10:32
  • 1
    Use the magento-deploy-ignore configuration in composer.json: stackoverflow.com/a/51961956/2534880
    – Sébastien
    Commented Nov 27, 2020 at 14:22

2 Answers 2

0

As per tecjam's comment, it is not possible.

Although not strictly a solution, you could make a copy of the .htaccess file outside of the magento installation directory.

When you want to update via composer you can check the .htaccess file's history on Magento's github for any changes, to ensure that you aren't missing crucial alterations to the file.

Then, once you have applied any updates to the version of the .htaccess file you copied outside of the magento directory, you can copy the file, or create a symlink, back into the magento installation folder.

Without utilising some additional package management software, this is probably the cleanest solution.

Although it may only prove useful when Magento updates are scheduled automatically, if you wish to use the .htaccess file you copied outside of the magento installation directory irrespective of any changes that may be made to the original, then you could create a cronjob by running crontab -e and specifying:

0 0 1 * * /usr/bin/rsync -a /path/to/file/outside/magento/directory/.htaccess /path/to/magento/directory/.htaccess

This example would replace the .htaccess file within the Magento installation directory at 12am on the 1st day of each month.

0

If you make .htaccess readonly permission

Allow write to it when you need to but otherwise protect it at other times

1
  • Although to throw in a curve ball. How we work is that we have a M2 build folder. We run build process on this. Then when we rsync build site to web root - we exclude files such as this in rysnc. Closest thing we can get to no down time deployment. Commented May 17, 2019 at 12:01

Your Answer

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

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