PHP路由 - 样式没有任何效果没有任何、路由、样式、效果

2023-09-02 11:40:23 作者:甜味拾荒者

我已经创建了一个基本的路由系统在PHP。 URL被分成数组,这样我可以决定如何根据不同的URL显示。(例如:www.domain.com/page/option/param)

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).

因此​​,在我的index.php我定义一个div的标题,内容和页脚,和/页/决定了内容的div中包含哪些文件。路由的工作原理,和HTML被加载,但样式表似乎并不如此。它也不工作时,我<链接> 样式表直接在文件(据说有可能在身体内链接样式,与attribude itemprop 而不是相对) - 反正,没有人知道这可能是造成这种

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:

.htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?uri=$1 [QSA,L]

我的路由使用 $ _ SERVER ['REQUEST_URI'] 获得的URL,然后我删除/指数,其余分成数组 - 这一切的作品罚款。

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.

在此先感谢。

推荐答案

使用假或友好的URL的大部分重写,你需要指定样式表的位置或者使用绝对路径或使用基地标记部分。

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.

例如。

<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

您可以在link标签的路径之前,使其开始在根目录下添加一个反斜杠。

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" />