You probably need to use headers, as I did.
For CSS
header('Content-type: css');
For JS
header('Content-type: application/javascript');
Since you're using your index.php page to parse all of this stuff, you'll need to include a whole lot of if statements. You should write a function like this:
- Code: Select all
function filename()
{
/**
Function Statement: takes $_SERVER['REQUEST_URI'] and strips from it the $_GET variable
Input
$_SERVER['REQUEST_URI']
Server-defined superglobal variable
Returns the page as requested in the URL minus anchor thingies (the ones that begin with #)
Process
$question=strstr($_SERVER['REQUEST_URI'],'?'); // returns everything after the first appearance of ?, if present
$name=str_replace($question,"",$localhost);
$GLOBALS['filename']=substr($name,1); //quick way of removing the first / (versus eregi_replace("^/",'',$name), for example)
Output
$GLOBALS['filename']
makes $filename available in the main page
*/
$name=str_replace($question,"",$localhost);
$filename=substr($name,1);
}
Now, keep in mind that, if you ever use <link rel="stylesheet" href="/csspage.css">, $_SERVER['REQUEST_URI'] becomes '/csspage.css' when that page is loading. The same idea goes for <script src="/javascriptpage.js"></script>. The same goes for include pages as far as I can tell. What this fact means is that, when you're writing your if statement in your index.php page, you'll need to accommodations, such as:
- Code: Select all
if($filename=='csspage.css')
{
header('Content-type: css');
echo file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/csspage.css'); //you don't really need $_SERVER['DOCUMENT_ROOT'], but I like to use it
}
elseif($filename=='javascriptpage.js')
{
header('Content-type: application/javascript');
echo file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/javascriptpage.js');
}
With the above function I wrote for you, all you'd need to do would be to call it with filename() in the files means that you won't need to utilise the $_GET[] variable since $_SERVER['REQUEST_URI'] will already hold the information $_GET[] would. $_SERVER['PHP_SELF'] will always be, for you, index.php, but, in this case, $_SERVER['REQUEST_URI'] is identical to $_GET['index']. With the function, you can accommodate for all $_GET[] requests in the URL bar. As well, you'll only need to write, in your .htaccess file:
- Code: Select all
RewriteEngine On
RewriteRule .* index.php