添加注释为.htaccess注释、htaccess

2023-09-02 00:33:53 作者:娘们的外表、爷们的心

为什么这项工作:

 重写规则(+)/ $ $ 1
 

和这部作品:

 重写规则(+)/ $ $ 1 [L] #bla BLA BLA
 

但这不起作用:

 重写规则(+)/ $ $ 1 #bla BLA BLA
 
word当页注释

解决方案

注释在.htaccess必须的开始的用

最后一个规则不起作用,因为评论是不是真正的意见。 htaccess的评论的必须开始的用(必须在一行的开始),而不是随意的任何地方。

在第二种情况下, #bla BLA BLA 是PTED作为一个第四个参数间$ P $的重写规则指令,它会被忽略。

在过去的情况下, #bla BLA BLA 是PTED作为第三个参数,除$ P $这在重写规则的情况是标志去了, #bla BLA BLA 这不就是mod_rewrite的任何标志的理解,所以你会得到一个错误。

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

解决方案

Comments in .htaccess must begin with a #.

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.