First time I've tried making pretty urls and this is my system, .htaccess maps everything back to index.php, index.php splits the URL into an array, then uses a case statement to decide how to proceed.
.htaccess:
RewriteBase /
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^.*$ ./index.php
index.php:
$request = $_SERVER['REQUEST_URI'];
#split the path by '/'
$params = explode("/", $request);
var_dump($params);
if(!isset($params[1]) || $params[1] == "") {
require_once('inc/content_default.php');
} else if ($params[1] == "posthandler"){
require_once('bin/posthandler.php');
} else {
switch($params[1]) {
case "dashboard":
include('inc/content_active.php?ign=' . $params[2]);
break;
}
}
The issue is that when the url is: [domain]/dashboard/AviateX14, I get the error:
Warning: include() [function.include]: Failed opening '/inc/content_active.php?ign=AviateX14' for inclusion (include_path='.:/opt/php-5.3/pear') in /home/u502822836/public_html/index.php on line 92
The file does exist, the issue is with the code, I know this because I've tested by putting in include('index.php') and it still fails. The file does exist at inc/content_active.php.
What am I doing wrong guys? :(
EDIT: var_dump of $params is :
array(3) { [0]=> string(0) "" [1]=> string(9) "dashboard" [2]=> string(9) "AviateX14" }
You can't have query strings in a php include()
, since that's not actually being requested. You'll have to fill in the parameters yourself in the server variables:
switch($params[1]) {
case "dashboard":
$_GET['ign']=$params[2];
include('inc/content_active.php');
break;
}