简体   繁体   English

在.htaccess中(。*)$和。* $有什么区别

[英]In .htaccess what is the difference between (.*)$ and .*$

When using rewrites, what is the difference between (. )$ and . 使用重写时,(。 )$和。之间有什么区别 $ for example in the two lines below: 例如,在以下两行中使用$:

RewriteRule ^blog/blog(.*)$ http://example.com/blog$1 [L,R=301]
RewriteRule ^blog/blog.*$ http://example.com/blog$1 [L,R=301]

Thanks 谢谢

Those two regex patterns themselves (.*)$ and .*$ mean the same thing: 这两个正则表达式模式本身(。*)$和。* $含义相同:

the . 的。 means any single character 表示任何单个字符
the * is the quantifier and means 0 or more occurrences of that any char *是量词,表示该字符的0次或多次出现
the $ is the end of string character... $是字符串字符的结尾...

The difference is that the first one uses a grouping with the parens. 不同之处在于,第一个使用与括号的分组。 It simply means that portion of the match (.*) can then be used in a back-reference with $#. 它仅表示匹配的部分(。*)随后可与$#一起用于反向引用。 So for the examples you gave: 因此,对于您给出的示例:

This makes sense since your $1 in the substitution has a grouping to pull from: 这是有道理的,因为替换中的$ 1有一个分组要从中提取:

RewriteRule ^blog/blog(.*)$ http://example.com/blog$1 [L,R=301]

This does not make sense since the $1 has nothing to pull from: 这是没有道理的,因为$ 1没有什么可拉的:

RewriteRule ^blog/blog.*$ http://example.com/blog$1 [L,R=301]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM