Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
646 views
in Technique[技术] by (71.8m points)

apache - Difference between $1 vs %1 in .htaccess

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

For example,

    #  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]

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

%1 Refers to a pattern matched in a RewriteCond condition, while $1 refers to a pattern matched inside a 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...