在查询字符串Apache的mod_rewrite变化的变量名 [英] APACHE mod_rewrite change variable name in query string

查看:90
本文介绍了在查询字符串Apache的mod_rewrite变化的变量名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在查询字符串来改变一个变量名,所以这是我的PHP code使用。

I'm trying to change a variable name in a query string, so it's usable by my PHP code.

查询得到来自外部系统的职位,所以我无法控制,他们是在它的空间发布的变量名。这使得它不可能的,我使用的PHP $ _ GET 功能。

The query gets posts from an external system, so I can't control that they are posting a variable name with a space in it. And that makes it impossible for me to use the PHP $_GET function.

我需要变量%20name 更改为?名new1

和我需要改变变量2为new2

And I need to change variable2 to new2

有许多变量在查询通过,但只有这两个需要改变。其余的可以保持不变,甚至消失。

There are many variables passed in the query, but only these two need to be changed. The rest can stay the same or even disappear.

所以变量%20name = ABC&放大器;变量2 = XYZ

需要落得为 =名new1 ABC&放大器; NEW2 = XYZ

另外,他们可能没有在此顺序,可能有更多的变量

Also, they may not be in this order and there may be more variables

所以变量%20name = ABC&放大器;等等= 123安培; blah2 = 456安培;变量2 = XYZ

So ?variable%20name=abc&blah=123&blah2=456&variable2=xyz

可能最终为 =名new1 ABC&放大器; NEW2 = XYZ

或作为 =名new1 ABC&放大器;等等= 123安培; blah2 = 456安培; NEW2 = XYZ

无论哪种方式就可以了!

Either way would be fine!

请给我在的mod_rewrite 规则,将解决这个问题。

Please give me the mod_rewrite rule that will fix this.

感谢你在前进!

推荐答案

解析查询字符串的mod_rewrite 是有点痛,一直要与<$完成C $ C>的RewriteCond ,并使用%N 在随后的重写规则,可能更容易更换手动打破了原有的查询字符串PHP。

Parsing the query string with mod_rewrite is a bit of a pain, has to be done with RewriteCond and using %n replacements in a subsequent RewriteRule, probably easier to manually break up the original query string in PHP.

完整的查询字符串可(在PHP)在 $找到_ SERVER ['QUERY_STRING']

The full query string can be found (within PHP) in $_SERVER['QUERY_STRING'].

您可以用其分解 preg_split()爆炸(),首先在&放大器; ,然后在 = ,要获得键/值对

You can split it up using preg_split() or explode(), first on &, then on =, to get key/value pairs.

使用自定义%20cbid = 123安培; blahblahblah&放大器;名称=例如作为一个例子

$params = array();
foreach (explode("&", $_SERVER['QUERY_STRING']) as $cKeyValue) {
    list ($cKey, $cValue) = explode('=', $cKeyValue, 2);
    $params[urldecode($cKey)] = urldecode($cValue);
}

// Would result in:

$params = array('custom cbid' => 123,
                'blahblahblah' => NULL,
                'name' => example);

这篇关于在查询字符串Apache的mod_rewrite变化的变量名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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