I am attempting to change a flexible title inside a query string, therefore it is functional by my PHP code.

The query will get posts from an exterior system, and so i can't control that they're posting a flexible title having a space inside it. Which causes it to be impossible that i can make use of the PHP $_GET function.

I have to change variable%20name to ?new1

And I have to change variable2 to new2

You will find many variables passed within the query, only both of these have to be transformed. The relaxation can stay as well as disappear.

So ?variable%20name=abc&variable2=xyz

Must finish as ?new1=abc&new2=xyz

Also, they might not be within this order there might be more variables

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

Could finish as ?new1=abc&new2=xyz

OR as ?new1=abc&blah=123&blah2=456&new2=xyz

In either case could be fine!

Please produce the mod_rewrite rule which will fix this.

Thanks ahead of time!

Parsing the query string with mod_rewrite is a little of the discomfort, needs to be achieved with RewriteCond and taking advantage of %n substitutes inside a subsequent RewriteRule, most likely simpler to by hand split up the initial query string in PHP.

The entire query string are available (within PHP) in $_SERVER['QUERY_STRING'].

You are able to split up using preg_split() or explode(), first on &, after that time =, to obtain key/value pairs.

Using custom%20cbid=123&blahblahblah&name=example for example.

$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);