Forum Moderators: phranque

Message Too Old, No Replies

htaccess "#" comment append to line throws errors.

         

kahuna

3:57 am on Mar 7, 2019 (gmt 0)

10+ Year Member



htaccess "#" comment append to line throws errors....

my sincerest apologies for posting this...
but all of a sudden today... after plus 10 years on my host...
and a couple of hours banging this against the wall with them...

All of a sudden today....
All my htaccess files that have/had a comment to a line in the htaccess file tossed out 500 errors.

"somecode_in_the_htaccess_file" # this comment tossed 500 errors for the line
.

for like.. 19 years now.... I "appended" the "#" comment to the line
in the htaccess file... never a problem.

I am on Unix.. not Windows server... at least that is what is has been..

Self taught on these things... Have I been wrong all this time..
obviously I fixed the problem editing numerous htaccess files...

geeshhh... I thought I would have seen this faux pas along the way...
Don't know why it just happened on my hosting company.


thanks again group... long.. long day...

phranque

4:13 am on Mar 7, 2019 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



strange!
as far back as apache 1.3:
Lines which begin with the hash character "#" are considered comments, and are ignored. Comments may not be included on a line after a configuration directive.

source: http://httpd.apache.org/docs/1.3/configuring.html#syntax

TorontoBoy

4:17 am on Mar 7, 2019 (gmt 0)

5+ Year Member Top Contributors Of The Month



I believe I did that when I started banning with htaccess, and Apache threw a hissy fit. It is a common programming language practice, but no, not for Apache. I really hope Apache will allow this in the future, as it would be very helpful. For now I wrote a script that, to keep my htaccess smaller I parse a line and if there is a "#" anywhere on the line I ignore it.

But these examples are not legit, and will produce an error:

ExpiresActive on # this will trigger an error
RedirectMatch 403 /spamhole/ # this will trigger an error
# this will
trigger an error

[htaccessbook.com...]

lucy24

4:41 am on Mar 7, 2019 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



am on Unix.. not Windows server... at least that is what is has been..
That may actually be relevant, because windows line breaks are CRLF (\r\n) while unix line breaks are LF (\n) alone, and possibly it applied its own definition of what constitutes a new line.

But probably not.

Have I been wrong all this time..
Apparently so, but at least it's an easy global replace.

My text editor does language-specific syntax highlighting. Things look quite picturesque in Apache mode when it meets a redirect involving # (fragment link with NE flag) because it thinks the rest of the line is a comment.

kahuna

10:57 am on Mar 7, 2019 (gmt 0)

10+ Year Member



That may actually be relevant, because windows line breaks are CRLF (\r\n) while unix line breaks are LF (\n) alone, and possibly it applied its own definition of what constitutes a new line.


as mentioned I am on Unix...

Interesting... because previous edits to the htacess... my lines all ended with \r\n...

When I looked at the file yesterday... they all ended with \n .
So.. somehow the Host must have changed previous all the lines ending with \r\n

thinking that was the problem I changed them all to \r\n...
And it doesn't throw a 500 error...
\r\n must be acceptable because many people do edit their file on a Windows machine.. or Mac.. which puts \r\n when you hit the "enter" button on the keyboard.

obviously I changed the offending lines that had a comment appended (on the same line as) to the "rule."
Which solved the problem.

All the offending lines with comments were on ip banning lines..
ie... an-ip-address # these guys are from the planet Mars

thanks again group !

wilderness

12:28 pm on Mar 7, 2019 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



for like.. 19 years now.... I "appended" the "#" comment to the line
in the htaccess file... never a problem.


And by appending to end of line, you've been doing so incorrectly for 19 years.

Directives in the configuration files are case-insensitive, but arguments to directives are often case sensitive. 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.

[httpd.apache.org...]

lucy24

6:19 pm on Mar 7, 2019 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



or Mac.. which puts \r\n when you hit the "enter" button on the keyboard.
Classic Mac used CR (\r) alone. OS X, being unix-based, uses LF (\n) alone. (The \r form is troublesome because not all RegEx engines recognize it as a line break; it's just another character in the \s family. In fact \r\n may not be recognized as line-final for anchoring purposes.) Does Enter on the numeric keypad create \r\n on some OS versions? I just checked; mine doesn't.