参数/反向引用限制数量的mod_rewrite [英] mod_rewrite number of parameters/back-references limitation
问题描述
显然有多少反向引用您可以在htaccess的访问限制(9)的RewriteRules ..
Apparently there is a limitation (9) on how many backreferences you can access in htaccess RewriteRules..
但是,我们有需要超过9个参数,像这样一个重写规则:
But we have a RewriteRule that requires more than 9 parameters, something like this:
RewriteRule ^([^/]+)/b([0-9]+)(/a([0-9]+))?(/v([0-9]+))?(,([0-9]+))?(/(ajax|share))?(,complete)?$ /index.php?control=sites&site=brands&control_file=version_select&name=$1&campaign_id=$2&answer=$4&page=$8&option=$10&video_id=$6&page_type=research [L]
那么,当您尝试访问$ 10,恰好是它使用了$ 1,将一个0就在旁边。
So what happens when you try to access "$10", is that it uses $1 and puts a 0 right next to it.
有没有人能解决这个问题,任何的替代解决方案或什么?
Has anybody been able to solve this problem, any alternative solutions or anything?
谢谢!
推荐答案
其实,你并不需要捕捉的一切。写非捕获组(使用介绍:
)为您不想重用的事情,这应该再给你一些喘息的空间。比较:
Actually, you don't need to capture everything. Write non-capturing groups (introduced with "?:"
) for the things you don't want to reuse, this should give you some breathing space again. Compare:
Yours: Mine:
------------------------- ---------------------------
^([^/]+)/b $1 ^([^/]+)/b $1
([0-9]+) $2 ([0-9]+) $2
(/a([0-9]+))? $4 (?:/a([0-9]+))? $3
(/v([0-9]+))? $6 (?:/v([0-9]+))? $4
(,([0-9]+))? $8 (?:,([0-9]+))? $5
(/(ajax|share))? $10! (?:/(ajax|share))? $6
(,complete)?$ $11! (,complete)?$ $7
但与单纯的mod_rewrite,你不能去高于9反向引用。如果您需要更多,使用另一种 - 例如捕获只有在改写的重要组成部分,并与URL在您的应用程序的其余部分做一些字符串处理
But with mod_rewrite alone, you can't go higher than 9 back-references. If you need more, use an alternative - for example capturing only the most important parts in rewrite and do some string-processing with the rest of the URL in your app.
这篇关于参数/反向引用限制数量的mod_rewrite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!