![](/img/trans.png)
[英]difference between ^ vs ^.*$ in Rewrite rule apache in htaccess
[英]Difference between $1 vs %1 in .htaccess
.htaccess 中的%1
和$1
有什么區別?
例如,
# to remove www
RewriteCond %{HTTP_HOST} ^(\w+)\.mydomain\.com [NC]
RewriteRule .* http://mydomain.com/%1 [R=301,L]
# versus
# RewriteRule .* http://mydomain.com/$1 [R=301,L]
我一直在使用Dave Child 的 .htaccess 備忘單和Jackol 的 .htaccess 備忘單以及Apache mod_rewrite 文檔,但額外的幫助會很棒。
%1
指的是在RewriteCond
條件中匹配的模式,而$1
指的是在RewriteRule
中匹配的模式。
更一般地,使用%n
來引用RewriteCond
條件正則表達式模式中的編號匹配,並使用$n
來引用RewriteRule
正則表達式模式中的編號匹配。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.