![](/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.