问题
I have created a basic Routing-system in PHP. The url is split into an array, so that i can decide what to show depending on the URL (ex: www.domain.com/page/option/param).
So in my index.php I've defined a div for header, content and footer, and the /page/ determines which file to include in the content-div. The routing works, and the HTML is loaded, but the stylesheet doesn't seem to be. Neither does it work when I <link>
the stylesheet directly in the file (and supposedly it's possible to link a stylesheet within the body, with the attribude itemprop
rather than rel
) - anyways, does anyone know what could be causing this?
.htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?uri=$1 [QSA,L]
My routing uses $_SERVER['REQUEST_URI']
to get the URL, and i then remove the /index and split the rest into an array - all of this works fine.
Thanks in advance.
回答1:
With most rewriting of "fake" or friendly URL's, you need to specify the location of the stylesheet either using absolute path
or using the base
tag in the head
section.
e.g.
<base href="http://example.com" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
//The CSS file above will load from http://example.com/css/style.css
OR
You can add a back slash before the path in the link tag so that it starts at the root directory.
<link href="/path/to/style.css" rel="stylesheet" type="text/css" />
来源:https://stackoverflow.com/questions/32912156/php-routing-stylesheets-have-no-effect