Why does this work:
RewriteRule (.+)/$ $1
and this work:
RewriteRule (.+)/$ $1 [L] #bla bla bla
but this doesn't work:
RewriteRule (.+)/$ $1 #bla bla bla
htaccess and . htpasswd files are protected from all external access. This is super important because you do not want anyone or anything to access these sensitive and powerful files.
. htaccess files (or "distributed configuration files") provide a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories thereof.
The last rule doesn't work because the comments aren't really comments. Comments in htaccess must begin with a #
(must be at the start of a line), and not arbitrarily anywhere.
In the second case, the #bla bla bla
is interpreted as a 4th parameter of the RewriteRule
directive, which is simply ignored.
In the last case, the #bla bla bla
is interpreted as a 3rd parameter, which in the RewriteRule
's case is where the flags go, and #bla bla bla
isn't any flags that mod_rewrite understands so you get an error.
Apache's config file format (of which .htaccess
files are one example) doesn't technically support inline comments, only full-line comments (i.e. a line beginning with a #
).
Lines that begin with the hash character "#" are considered comments, and are ignored. Comments may not be included on a line after a configuration directive. -- Official Apache 2.4 manual
Confusingly, though, each module gets to parse the input for its directives however it likes - so mod_rewrite
decides what to do with any line beginning with RewriteRule
I don't know for sure but my guess is that mod_rewrite
is ignoring everything after the [flags]
, and the #
isn't actually necessary at all.
Best bet, though, is to always keep comments to their own line, since that will work whatever the directive you're commenting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With