Support » Plugins » Hacks » [Plugin: Redirection] QueryStrings on Pass Through to Target with QueryString

  • I was having trouble doing a passthrough to a page with query string values, but that might also have additional querystring values. For example:

    Type: pass through
    Regex: ^/page/view/
    Target: ^/target.php?action=view
    Request: /page/view/?id=1
    URI: /target.php?action=view?id=1

    I modified pass.php to correct this issue (as well as set $_REQUEST in addition to $_GET) by replacing lines 37-42:

    $_SERVER['REQUEST_URI'] = $target;
    if (strpos ($target, '?'))
    {
    	$_SERVER['QUERY_STRING'] = substr ($target, strpos ($target, '?') + 1);
    	parse_str ($_SERVER['QUERY_STRING'], $_GET);
    }

    with the following:

    $_SERVER['REQUEST_URI'] = $target;
    if (strpos ($target, '?'))
    {
    	$front = substr($target, 0,strpos ($target, '?') + 1);
    	$qsa = str_replace( '?', '&', substr($target, strpos ($target, '?') + 1));
    	parse_str ($qsa, $_GET);
    	parse_str ($qsa, $_REQUEST);
    	$_SERVER['REQUEST_URI'] = $front.$qsa;
    	$_SERVER['QUERY_STRING'] = $qsa;
    }

    Results
    $_SERVER[‘REQUEST_URI’] = “/target.php?action=view&id=1”
    $_SERVER[‘QUERY_STRING’] = “action=view&id=1”;
    $_GET = array ( “action”=>”view”, “id”=>”1” )
    $_REQUEST = array ( “action”=>”view”, “id”=>”1” )

    http://wordpress.org/extend/plugins/redirection/

Viewing 1 replies (of 1 total)
  • Thread Starter lukewarmmizer

    (@lukewarmmizer)

    This is what I finally went with – lets me rewrite the login page for example:

    $_SERVER['REQUEST_URI'] = $target;
    $index = (strpos($target,'?'))? strpos($target,'?') : strlen($target);
    $front = substr($target, 0, $index);
    $qsa = str_replace( '?', '&', substr($target, strpos ($target, '?') + 1)); // append qsa
    if (strpos ($target, '?')) {
    	parse_str ($qsa, $_GET);
    	parse_str ($qsa, $_REQUEST);
    	$_SERVER['REQUEST_URI'] = $front.'?'.$qsa;
    	$_SERVER['QUERY_STRING'] = $qsa;
    }
    if (strlen($front)-strpos ($front, '.php')==4){ // ends with php, include the file
    	include ($_SERVER['DOCUMENT_ROOT'].$front);
    	exit ();
    }
Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: Redirection] QueryStrings on Pass Through to Target with QueryString’ is closed to new replies.