Recovering HTTP $_GET variables when using Apache’s mod_rewrite

May 13th, 2010 | Posted in PHP

Anyone using Apache’s mod_rewrite to handle HTTP requests will know that your $_GET variables  are no longer recognised by the server as the URI is treated as a single string value.

PHP has a function, called mb_parse_str(), that parses the query string representation of an array into a multi-dimensional array. This can be used to correctly represent the query string part of the URL.

The below function returns an array that holds the same values you’d expect from $_GET.

function get_http_vars(){
  $query = parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY);
  mb_parse_str($query, $get);
  return $get;
}

To use the function simply follow the example below;

$get = get_http_vars();

3 Responses to “Recovering HTTP $_GET variables when using Apache’s mod_rewrite”

  1. WP Themes | June 11, 2010 at 11:42 pm

    Amiable dispatch and this mail helped me alot in my college assignement. Thank you on your information.

  2. Wordpress Themes | June 24, 2010 at 9:50 pm

    Genial post and this mail helped me alot in my college assignement. Thanks you on your information.

  3. Wordpress Themes | July 2, 2010 at 6:07 am

    Nice post and this mail helped me alot in my college assignement. Thank you for your information.

Leave a Reply

© 2006 - 2010 Matt Lowden. Creative Commons all rights reserved.