500 Error from appending to last line in htaccess
-
There seems to be a long-standing bug that causes W3 Total Cache to write its .htaccess rules starting on the end of the last line in the file. I ran several test installations across two different hosts (to rule out the host) to chase this down to find a trigger.
So here is how this works. Single site installations of WordPress will write its own .htaccess rewrite rules surrounded by two comments, “# BEGIN WordPress” and “# END WordPress”. When W3TC writes rules, it apparently looks for the BEGIN comment. If it finds it, the rules prepend the WordPress ones (in other words, they get placed before the # BEGIN comment). If it doesn’t find it, it appends them to the end of the document. Since there usually isn’t a line break at the end of the file, this will typically make W3TC run into the last written line, with the W3TC starting comment being placed at the end of whatever line is there.
If that line happens to be a comment, no big deal. If it isn’t, you get a 500 error when Apache freaks out because it doesn’t know what to do.
This is especially troublesome for multisite because the rewrite rules are not surrounded by the BEGIN and END comments. Once W3TC writes to the file, the 500 error happens until the file is manually edited.
Since this has been happening for a while, I’m wondering when this will be corrected. It seems that if W3TC doesn’t see the # BEGIN comment, it either thinks the file is empty or it just doesn’t know where to put the code.
- The topic ‘500 Error from appending to last line in htaccess’ is closed to new replies.