mod_rewrite 参数数量/反向引用限制 [英] mod_rewrite number of parameters/back-references limitation

查看:23
本文介绍了mod_rewrite 参数数量/反向引用限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然,您可以在 htaccess RewriteRules 中访问多少个反向引用存在限制 (9).

但是我们有一个需要超过 9 个参数的 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.

有没有人能够解决这个问题,任何替代解决方案或任何东西?

谢谢!

解决方案

实际上,您不需要捕获所有内容.为您不想重复使用的东西编写非捕获组(用 "?:" 引入),这应该再次给您一些喘息的空间.比较:

<前>你的: 我的:------------------------- -------------------------——^([^/]+)/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 美元(,完成)?$ 11!(,完整)?$ 7

但是单独使用 mod_rewrite,您不能超过 9 个反向引用.如果您需要更多,请使用替代方法 - 例如,仅捕获重写中最重要的部分,并对应用中 URL 的其余部分进行一些字符串处理.

Apparently there is a limitation (9) on how many backreferences you can access in htaccess RewriteRules..

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]

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?

Thanks!

解决方案

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

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屋!

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