阿帕奇 rewrite_rule 用于 angularjs

Apache rewrite_rule for angularjs

我在 Angularjs 应用程序中有此规则。它完美地工作。但我想了解一条规则,但我不知道它的作用 RewriteRule ^.*$ - [NC,L] #???

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -!f 
RewriteRule ^.*$ - [NC,L] #NC none-case-sensitive, L stop when match
RewriteRule ^(.*) index.html [NC,L] 

请在这条规则上帮助我 RewriteRule ^.*$ - [NC,L] 我知道 [NC,L] 标志,但我不明白 ^.*$ - 尤其是规则末尾的空破折号。

RewriteRule 的语法是:

RewriteRule Pattern Substitution [flags]

您的规则是:

RewriteRule ^.*$ - [NC,L]
  • ^.*$ 是一个 perl 兼容的正则表达式,其中

    • ^ 是字符串的开始
    • .是除换行符外的任何字符
    • *表示0次或多次
    • $ 是字符串的结尾。
  • 替换为-,意思是:"no substitution should be performed (the existing path is passed through untouched). This is used when a flag needs to be applied without changing the path."

  • flags是NCL,意思是:

    • NC:使模式比较不区分大小写。
    • L:立即停止重写过程,不再应用任何规则。特别注意每个目录和 .htaccess 上下文的注意事项(另请参阅 END 标志)。

所以这个规则匹配任何东西,不做任何替换,并立即停止重写过程。