2011-07-11 96 views
22

.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's .htaccess cheat sheetJackol's .htaccess cheat sheet还有Apache mod_rewrite docs但更多的帮助将是巨大的。

+5

'mod_rewrite'文档说'%N'反向引用是针对RewriteCond模式的,而'$ N'反向引用是针对RewriteRule模式的。 – BoltClock

回答

40

%1指与RewriteCond条件相匹配的模式,而$1指的是与RewriteRule内部匹配的模式。

更一般地,使用%nRewriteCond条件的正则表达式模式参考编号匹配,并使用$nRewriteRule正则表达式模式参考编号匹配。

相关问题