1
我遇到了使用mod_rewrite啓用$ _GET變量的問題。我有以下的.htaccess:
RewriteEngine On
RewriteRule ^/?Resource/(.*)$ /$1 [L]
RewriteRule ^$ /home [redirect]
RewriteRule ^([a-zA-Z]+)/?([a-zA-Z0-9/]*)$ /app.php?page=$1&query=$2 [L]
和app.php是:
<?php
require("controller.php");
$app = new Controller();
和Controller.php這樣的:
<?php
require("model.php");
require("router.php");
class Controller{
//--------Variables------------
private $model;
private $router;
//--------Functions------------
//Constructor
function __construct(){
//initialize private variables
$this->model = new Model();
$this->router = new Router();
$page = $_GET['page'];
//Handle Page Load
$endpoint = $this->router->lookup($page);
if($endpoint === false) {
header("HTTP/1.0 404 Not Found");
}else {
$this->$endpoint($queryParams);
}
}
private function redirect($url){
header("Location: /" . $url);
}
//--- Framework Functions
private function loadView($view){
require("views/" . $view . ".php");
}
private function loadPage($view){
$this->loadView("header");
$this->loadView($view);
$this->loadView("footer");
}
//--- Page Functions
private function indexPage(){
$this->loadPage("home");
}
private function controlPanel(){
echo "Query was " . $code;
/*
if($this->model->set_token($code)){
$user = $this->model->instagram->getUser();
}else{
echo "There was an error generating the Instagram API settings.";
}
*/
$this->loadPage("controlpanel");
}
private function autoLike(){
$this->loadPage("autolike");
}
private function about(){
$this->loadPage("about");
}
}
因此,一個URL的一個例子,我可能有是/app.php?page=controlpanel & query = null將被重寫爲/ controlpanel。我遇到的問題是我有另一個頁面發送一個表單到/ controlpanel,導致像/ controlpanel?code = somecode這樣的URL。
我想要做的是得到$ _GET ['代碼'],我似乎無法做到這一點。誰能幫忙?提前爲一些代碼轉儲道歉。
@jcsanyi對行爲的簡要說明 – Orangepill
@jcsanyi我將它合併到答案中 – Orangepill