mod_rewrite number of parameters/back-references limitation

后端 未结 3 1989
臣服心动
臣服心动 2020-12-19 13:47

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 paramet

3条回答
  •  感情败类
    2020-12-19 14:01

    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.

提交回复
热议问题