• Hey guys,

    WordFence has broken my .htaccess file again. It is completely empty.

    Can you please add in some code that makes a backup copy of .htaccess before writing changes? Check the file size of .htaccess and if it is greater than 0 please try to make a backup of it ( .htaccess.pre_falcon or something )

    This happens when the hosting account runs out of disk space. It clears the .htaccess file but is unable to write the new contents to it.

    So please check that making a backup of the .htaccess file worked first (that will let you know if there is free disk space) and then if the backup worked proceed to write the new .htaccess file content.

    Do not backup a 0 byte .htaccess file

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter dtbaker

    (@dtbaker)

    Hi dtbaker,
    Wordfence only writes to .htaccess in two situations.

    1. Falcon cache. This feature of Wordfence is being removed soon and we are encouraging all users of Falcon to find a suitable replacement.

    2. When the Firewall is optimized. This only happens once when the Firewall is manually optimized. Running out of disk space while optimizing the Firewall sounds like extremely bad luck but I suppose it could happen. Is this what happened to you?

    Let me know if can give me any more details on the scenario you experienced. Thanks!

    Had same “.htaccess 0 bytes” case at a customer website 3 weeks ago with falcon cache enabled and some blocked IPs which were added as deny lines in .htaccess. Firewall was off, only login-blocking and cache was on.

    Customer edited parts of site at the time when .htaccess went blank with many quick changes and frequent custom calls to wfCache::clearPageCache(); which by reading the cache-source should not be a problem but maybe could have triggered some race condition…

    Have since then switched to free version of WP Fastest Cache as Wordfence will/has dropped the falcon cache support anyway, too bad.

    Thread Starter dtbaker

    (@dtbaker)

    Thanks for the heads up about Falcon.

    Yes I’m not really sure if it’s Falcon or Firewall, whatever was trying to re-write the .htaccess file while the server was trying to write backups/emails/logs/whatever to any free remaining space it could.

    We’re migrating hosts so hopefully can make use of the caching provided by the new hosts and continue to use the core wordfence security features.

    Hi again,
    It may have been Falcon then. If it ever happens again after you have stopped using Falcon please let us know.

    Good luck with the move!

    It must be said, if nothing else, backup your .htaccess file, multiple backups! Easy to do, if you use some sort of FTP capable editor, just save various versions of .htaccess under different names. Example, .htaccess-backup-48 and so on. Then, who cares what software messes with your .htaccess, just copy over the bogus version. MTN

    Thread Starter dtbaker

    (@dtbaker)

    Yes backups handled fine and was able to restore htaccess quickly πŸ™‚

    Sounds great dtbaker! I’m setting this to resolved for now but do get back in touch if you have further issues.

    Thread Starter dtbaker

    (@dtbaker)

    Hey guys,

    Woke up again this morning to an empty .htaccess file.

    16GB free space. So it isn’t disk space that is causing this issue, as previously thought. Something else is causing this.

    $ ls -l .htaccess
    -rw-r–r– 1 dtbaker psacln 0 Oct 24 03:48 .htaccess

    $ df -h
    Filesystem Size Used Avail Use% Mounted on
    /dev/xvde1 178G 153G 16G 91% /

    Hi again,
    as long as you don’t have Falcon enabled I’m fairly certain there has to be some other plugin that is doing this. My best suggestion would be to search all plugin files for the string “htaccess” to try and determine which plugin might be doing it. Looking at the last modified timestamp on the file might give you some clues as well. Another option might be to remove write permissions from the file. Then you could check error logs after a few days. If you are lucky there could be a log entry there of a script that tried to write to it but failed.

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘WordFence breaks .htaccess file’ is closed to new replies.