在apache配置中创建变量 [英] Creating variable in apache config
本文介绍了在apache配置中创建变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的apache配置如下:
I have an apache config something like below:
RewriteCond %{QUERY_STRING} ^site=(eu|jp|in)$ [NC]
RewriteRule ^/?fetchHomePage.action$ https://example.com/%1? [R=301,L,NC]
RewriteCond %{QUERY_STRING} (?:^|&)site=(eu|jp|in)(?:&|$) [NC]
RewriteRule ^/?fetchFirstPage.action$ https://example.com/firstPage/%1? [R=301,L,NC]
RewriteCond %{QUERY_STRING} (?:^|&)site=(eu|jp|in) [NC]
RewriteRule ^/?fetchSecondPage.action$ https://example.com/secondPage/%1? [R=301,L,NC]
我可以在一些变量中存储(eu | jp | in)"并在所有三个重写规则中重用该变量吗?
Can I store "(eu|jp|in)" in some variable and reuse that variable in all the three rewrite rules?
这里的铅被赞赏了吗?
推荐答案
(eu|jp|in)
实际上是一个正则表达式.您实际上不能将该部分存储在变量中,但是可以使用env变量来避免重复相同的条件:
(eu|jp|in)
is actually a regex expression. You can't really store that part in a variable but you can use a env variable to avoid repetition of same conditions as this:
# set env var QS if quesry string has site=(eu|jp|in)
RewriteCond %{QUERY_STRING} (?:^|&)site=(eu|jp|in)(?:&|$) [NC]
RewriteRule ^ - [E=QS:%1]
# now use value stored in QS variable
RewriteCond %{ENV:QS} ^(.+)$
RewriteRule ^/?fetchHomePage\.action$ https://example.com/%1? [R=301,L,NC]
RewriteCond %{ENV:QS} ^(.+)$
RewriteRule ^/?fetchFirstPage\.action$ https://example.com/firstPage/%1? [R=301,L,NC]
RewriteCond %{ENV:QS} ^(.+)$
RewriteRule ^/?fetchSecondPage\.action$ https://example.com/secondPage/%1? [R=301,L,NC]
这篇关于在apache配置中创建变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文