php - Getting $_GET variable when using mod_rewrite -
i having issues getting $_get variables mod_rewrite enabled. have following .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]
and app.php is:
<?php require("controller.php"); $app = new controller();
and controller.php is:
<?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 " . $code; /* if($this->model->set_token($code)){ $user = $this->model->instagram->getuser(); }else{ echo "there error generating instagram api settings."; } */ $this->loadpage("controlpanel"); } private function autolike(){ $this->loadpage("autolike"); } private function about(){ $this->loadpage("about"); } }
so example of url might have /app.php?page=controlpanel&query=null rewritten /controlpanel. problem have have page sends form /controlpanel resulting in url /controlpanel?code=somecode.
what trying $_get['code'] , cannot seem this. can help? apologies in advance bit of code dump.
change
rewriterule ^([a-za-z]+)/?([a-za-z0-9/]*)$ /app.php?page=$1&query=$2 [l]
to
rewriterule ^([a-za-z]+)/?([a-za-z0-9/]*)$ /app.php?page=$1&query=$2 [l,qsa]
qsa append query string
from docs
"when replacement uri contains query string, default behavior of rewriterule discard existing query string, , replace newly generated one. using [qsa] flag causes query strings combined."
Comments
Post a Comment