简体   繁体   English

htaccess rewriterule-逃逸反向引用B标志替代

[英]htaccess rewriterule - escape backreferences B flag alternative

I'm trying to rewrite a url that contains the & symbol. 我正在尝试重写包含&符号的网址。 I've tried with & and %26, but both get stripped out by apache. 我曾尝试使用&和%26,但都被apache剥离。

For example, if the url is: 例如,如果URL为:

healthyliving/fruit/apples_&_pears

and the rewriterule is: 重写是:

RewriteRule ^healthyliving/fruit/([^/.]+)$ food.php?subpage=healthyliving&item=$1 [QSA,L]

The querystring would show "apples_& pears", but _GET['item'] would show "apples ". 查询字符串将显示“ apples_& pears”,但_GET['item']将显示“ apples ”。

From what I've read, most solutions use the B flag to escape backreferences. 根据我的阅读,大多数解决方案都使用B标志来逃避反向引用。 This flag was introduced in 2.2.7. 该标志在2.2.7中引入。 Unfortunately we are running an earlier version and we cannot updgrade right now for various reasons. 不幸的是,我们运行的是早期版本,由于种种原因,我们现在无法升级。

Is there a way to achieve what I need without the use of the B flag? 有没有一种方法可以实现我不需要的B标志?

I'm not entirely sure what you're trying to accomplish with the $_GET, but you could try this 我不确定您要使用$ _GET来完成什么,但是您可以尝试使用

RewriteRule ^healthyliving/fruit/(.*)_&_(.*) food.php?subpage=healthyliving&item[]=$1&item[]=$2 [QSA,L]

Which should give you: 哪个应该给你:

Array ( [subpage] => healthyliving [item] => Array ( [0] => apples [1] => pears ) ) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM