i have a dynamic php web page
localhost/ctd/index.php
All working good except if i add a forward slash to it like below:
localhost/ctd/index.php/
the css doesnt load..
is this a css bug or PHP?
The full code of index.php
<?php
define('pageaccess', TRUE);
$action = $_GET['p'];
include "views/header.php";
if($action=='student')
{
include "views/student.php";
}else if($action=='college'){
include "views/college.php";
}else if($action==''){
include "views/home.php";
}else{
include "views/404.php";
}
include "views/footer.php";
?>
CSS link
<link rel="stylesheet" type="text/css" href="css/ctdu_style.css" />
Point me to the right direction.
Thanks
The problem is that your link is relative.
For example, if you have link like this:
<link rel="stylesheet" href="css.css">
And you're currently at http://localhost/example.php/ then it loads http://localhost/example.php/css.css. It's server-specific thing, some servers implement this "feature", some not. The browser thinks it's directory, while in fact it isn't. Some PHP scripts use this behavior, for example MediaWiki uses index.php as directory to emulate .htaccess when server doesn't support .htaccess files, but supports CGI scripts as directories.
The solution would be either making sure that every path uses page root instead of current directory (for example /css.css instead of css.css).
Second solution would be sort of hacky, but would convert links. Don't use if you actually want to use this sort of links (but I doubt this :P).
<?php
$request_uri = preg_replace('/\?.*/', '', $_SERVER['REQUEST_URI']);
if ($request_uri !== $_SERVER['SCRIPT_NAME']) {
header('Location: ' . $_SERVER['SCRIPT_NAME']);
exit;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With