命令mysite.com?page=forum
将运行在mysite的根目录下的index.php文件。
所以,你需要编写一些代码在index.php文件重定向到正确的地方,如
<?php
if (isset($_GET, $_GET['page'])) {
// sanitize the $_GET contents
switch ($_GET[['page']) {
case 'form' :
header('Location: sections/forum.php');
exit;
break;
case '...' :
// etc etc
}
} else {
echo 'No $_GET';
}
遗憾的是它并没有就此止步,因为它有可能你会想在把其他参数查询字符串以及page
。所以现在你必须决定如何处理这些其他参数。你把它们添加到header()
或者你把它们存储在其他地方,并确保你的其他应用程序知道从哪里得到它们。
<?php
if (isset($_GET, $_GET['page'])) {
// sanitize the $_GET contents
$gets = $_GET;
unset($gets['page'];
$qs = '?' . implode('&',$gets);
switch ($_GET[['page']) {
case 'form' :
header('Location: sections/forum.php' . $qs);
exit;
break;
case '...' :
// etc etc
}
} else {
echo 'No $_GET';
}
如果你使用GET,它可能会像这样工作,如果你这样写? – Naruto 2014-10-10 08:51:55