gpt4 book ai didi

php - CSS 文件未使用 mod_rewrite 加载

转载 作者:行者123 更新时间:2023-11-28 04:07:47 25 4
gpt4 key购买 nike

我在使用 mod_rewrite 时遇到了一个奇怪的问题。

我的 .htaccess 文件中有这段代码

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^info/([^/]+) article.php?id=$1 [L]

它似乎可以工作,因为我能够重写

localhost/article.php?id=1

localhost/info/1

但问题是,当我转到页面时,CSS 没有加载,我只显示了内容。我有一个 php 文件,我通过调用函数在其中编写了标题

echo "
<!DOCTYPE html>
<html lang='it'>
<head>
<title>Website</title>
<meta charset='utf-8'>
<link href='css/style.css' rel='stylesheet' type='text/css'>
<link href='css/index.php' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet'>
<link rel='stylesheet' href='css/font-awesome/css/font-awesome.min.css'>
<script src='javascript/jquery-3.1.1.min.js'></script>
</head>";

我也试过在“css/style.css”之前添加斜杠,得到“/css/style.css”,但似乎不起作用。

有什么建议吗?感谢您的建议。

最佳答案

使用绝对路径添加/到 URL:

echo "
<!DOCTYPE html>
<html lang='it'>
<head>
<title>Website</title>
<meta charset='utf-8'>
<link href='/css/style.css' rel='stylesheet' type='text/css'>
<link href='/css/index.php' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet'>
<link rel='stylesheet' href='/css/font-awesome/css/font-awesome.min.css'>
<script src='/javascript/jquery-3.1.1.min.js'></script>
</head>";

关于php - CSS 文件未使用 mod_rewrite 加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42880578/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com