Adding comments to .htaccess

user1032531 picture user1032531 · Feb 28, 2014 · Viewed 61.8k times · Source

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

Answer

Jon Lin picture Jon Lin · Feb 28, 2014

Comments in .htaccess must be on their own line, not appended to other statements.

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.