I want to redirect all traffic to one page where I decide what to output based on the URL the user entered. So far it works fine, the only thing that does not work is loading the stylesheet. Currently I tried all of it locally with XAMPP.
I reduced the code to a minimum to point out the problem.
.htaccess:
RewriteEngine on
RewriteRule ^((?!test\.php).+)$ /test.php [L]
Everything except test.php is rewritten to test.php
test.php:
<?php
$path = $_SERVER['REQUEST_URI'];
// remove any slashes in front of the path
$path = ltrim($path, '\\');
$path = ltrim($path, './');
if (pathinfo($path, PATHINFO_EXTENSION) == "css") {
readfile($path);
}
else {
echo("<!DOCTYPE html>\n");
echo("<html>\n");
echo("<head>\n");
echo("<link rel='stylesheet' href='/stylesheets/test-style.css' />\n");
echo("</head>\n");
echo("<body>\n");
echo("<h2>Test Heading</h2>\n");
echo("</body>\n");
echo("</html>\n");
}
?>
I check the file extension, if it is CSS, I output the file, if not I write some HTML code line by line.
test-style.css:
h2 {
color: yellow;
}
If I open any address in the browser, the HTML is shown but the stylesheet is not applied. Everything else works (I can load a favicon, javascript works), but not the stylesheet. I could directly output the code inside '' tags but of course, that is not a good solution. If I use the inspector of firefox I see that the stylesheet is there and if I change a line it suddenly applies.
Any ideas why this is not working or maybe a suggestion on how to achieve the desired results in a different way? Cleaning the browser cache or changing browser has no effect.
cssextension, you dont output any HTML so there is nothing to see on the page