1

为什么在使用干净的 url 时没有将查询字符串添加到 GET 数组中?例如。使用/foo/bar?stack=overflow$_GET['stack']变量为空。

我正在使用以下代码实现干净的 url:

$request = rawurldecode($_SERVER['REQUEST_URI']);

// Extracts the index.php file path (eg. /my_app)
// There is no need to specify the path to index.php as the script handles it
$path_to_index = str_ireplace($_SERVER['DOCUMENT_ROOT'].'/', '', $_SERVER['SCRIPT_FILENAME']);
$path_to_index = str_ireplace('/'.basename($_SERVER['SCRIPT_FILENAME']), '', $path_to_index);

    // Get rid of the path to index.php
$request = str_ireplace($path_to_index, '', $request);

// Get rid of index.php in the URL
$request = str_ireplace(basename($_SERVER['SCRIPT_FILENAME']), '', $request);

// Our URL is now clean so we can explode
$request = explode('/', $request);

// Delete empty and reindex
$request = array_values(array_filter($request)); 
4

3 回答 3

2

如果在 .htaccess 中使用 RewriteRules

在你的RewriteRule行末[QSA]这样写:

RewriteRule (.*) index.php?stuff=$1 [QSA]

QSA 标志信息:http ://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_qsa

于 2012-07-06T21:27:32.143 回答
0

也许是 b/c 你没有使用 $_GET ?GET 不是变量,但这应该可以正常工作......

于 2012-07-06T21:26:38.640 回答
0

您可能忘记在全局变量名称中使用下划线(“_”)。

尝试使用 $_GET['stack']。

于 2012-07-06T21:37:29.297 回答