.htaccess 中 $1 与 %1 之间的差异 [英] Difference between $1 vs %1 in .htaccess

查看:39
本文介绍了.htaccess 中 $1 与 %1 之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.htaccess 中的 %1$1 有什么区别?

What is the difference between %1 and $1 in .htaccess?

例如

    #  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 文档 但额外的帮助会很棒.

I have been using Dave Child's .htaccess cheat sheet and Jackol's .htaccess cheat sheet as well as the Apache mod_rewrite docs but additional help would be great.

推荐答案

%1 指的是在 RewriteCond 条件下匹配的模式,而 $1 指的是在 RewriteRule 中匹配的模式.

%1 Refers to a pattern matched in a RewriteCond condition, while $1 refers to a pattern matched inside a RewriteRule.

更一般地,使用 %n 引用来自 RewriteCond 条件正则表达式模式的编号匹配,并使用 $n 引用编号匹配来自 RewriteRule 正则表达式模式.

More generically, use %n to refer to the numbered matches from RewriteCond condition regex patterns, and use $n to refer to numbered matches from RewriteRule regex patterns.

这篇关于.htaccess 中 $1 与 %1 之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆