2

Tonight I upgraded my VPS from Ubuntu 16.04 LTS to Ubuntu 18.04 LTS. Everything worked as expected, had a little cleanup on php aisle 5.6 and some stocking shelves on php aisle 7.4. Apache restarted without a whimper after all my config and mod changes; thought I was good to go. But 3 of my 4 sites would not load; no clean 404 page, just this misconfiguration message.

Internal Server Error 
The server encountered an internal error or misconfiguration and was unable to complete your request.

After reviewing the /var/log/apache2/error.log, I found this:

[Wed May 06 03:55:16.190469 2020] [core:alert] [pid 5657] [client 10.10.10.10:56897] 
/var/www/abc/example.com/.htaccess: No comments are allowed here, referer: https://example.com/

After trying several different things, it seems that comments that start the line are NOT the issue, it is comments that end a normal line of the file. Removing or moving these #main office comments to their own lines bring everything back online. The # Allow from this IP address line is still in my .htaccess file but does not cause me any grief.

<Files wp-login.php>
    order deny,allow
    Deny from all
#   
#   Allow from this IP address
    allow from 10.10.10.10      #main office
    allow from 10.10.11.10      #satellite office
</Files>

Is this a 'bug' or a 'feature'? A search in Google for ".htaccess: No comments are allowed here" brings up almost nothing. (You know you are in trouble when the 4th hit is in a foreign language). Obviously the jump to Ubuntu 18.04 or the associated apache or php updates are the 'when', but WHY? Why is this in-line documentation problematic? What gives?

1

1 Answer 1

6

This is a feature and comes from Apache's configuration syntax:

Lines that begin with the hash character "#" are considered comments, and are ignored. Comments may not be included on the same line as a configuration directive. White space occurring before a directive is ignored, so you may indent directives for clarity. Blank lines are also ignored.

This hasn't changed recently: it's been the same in Apache 1.3. If these errors appeared after an upgrade, it's possible that these .htaccess files weren't even used before. It's also recommended to avoid using .htaccess unless absolutely necessary.

4
  • What is the recommended replacement? There must be some advantage in restricting the wp-admin from anyone in the world that wants to pound on it?!?
    – wruckie
    Commented May 6, 2020 at 12:49
  • This has nothing to do with limiting the access, as it's about the comments, alone. Simply remove the comments from these lines. You could put the comments on separate lines, if you still need them. Commented May 6, 2020 at 12:57
  • Please clarify -- "It's also recommended to avoid using .htaccess unless absolutely necessary." sounds like it is about more than comments.
    – wruckie
    Commented May 6, 2020 at 14:18
  • On the cited sentence, there's a hyperlink to the official Apache documention on When (not) to use .htaccess files. Daniel Morell explains this in more detail in Don't Use .htaccess Unless You Must. Or Andrew Welch in Stop using .htaccess files! No, really.. Commented May 6, 2020 at 14:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .