![](/img/trans.png)
[英].htaccess: What's the difference between "RewriteRule ^ -" and "RewriteRule ^(.*)$ /$1"?
[英]In .htaccess what is the difference between (.*)$ and .*$
使用重写时,(。 )$和。之间有什么区别。 例如,在以下两行中使用$:
RewriteRule ^blog/blog(.*)$ http://example.com/blog$1 [L,R=301]
RewriteRule ^blog/blog.*$ http://example.com/blog$1 [L,R=301]
谢谢
这两个正则表达式模式本身(。*)$和。* $含义相同:
的。 表示任何单个字符
*是量词,表示该字符的0次或多次出现
$是字符串字符的结尾...
不同之处在于,第一个使用与括号的分组。 它仅表示匹配的部分(。*)随后可与$#一起用于反向引用。 因此,对于您给出的示例:
这是有道理的,因为替换中的$ 1有一个分组要从中提取:
RewriteRule ^blog/blog(.*)$ http://example.com/blog$1 [L,R=301]
这是没有道理的,因为$ 1没有什么可拉的:
RewriteRule ^blog/blog.*$ http://example.com/blog$1 [L,R=301]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.