PHP Routing - stylesheets have no effect

时光毁灭记忆、已成空白 提交于 2020-01-11 14:23:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!