$rewrite_to) { // We have a match! if (preg_match($rule, $request_uri)) { $rewritten_url = preg_replace($rule, $rewrite_to, $request_uri); $url_parts = explode('?', $rewritten_url); // If there is a query string if (isset($url_parts[1])) { $query_string = explode('&', $url_parts[1]); // Set $_GET properly for all of the variables // We also set $_REQUEST if it's not already set foreach ($query_string as $cur_param) { $param_data = explode('=', $cur_param); // Sometimes, parameters don't set a value (eg: script.php?foo), so we set them to null $param_data[1] = isset($param_data[1]) ? $param_data[1] : null; // We don't want to be overwriting values in $_REQUEST that were set in POST or COOKIE if (!isset($_POST[$param_data[0]]) && !isset($_COOKIE[$param_data[0]])) $_REQUEST[$param_data[0]] = urldecode($param_data[1]); $_GET[$param_data[0]] = urldecode($param_data[1]); } } break; } } // If we don't know what to rewrite to, we show a bad request messsage if (empty($rewritten_url)) { header('HTTP/1.x 404 Not Found'); // Allow an extension to override the "Bad request" message with a custom 404 page ($hook = get_hook('re_page_not_found')) ? eval($hook) : null; error('Page Not found (Error 404): The requested page '.forum_htmlencode($request_uri).' could not be found.'); } // We change $_SERVER['PHP_SELF'] so that it reflects the file we're actually loading $_SERVER['PHP_SELF'] = str_replace('rewrite.php', $url_parts[0], $_SERVER['PHP_SELF']); require FORUM_ROOT.$url_parts[0];