CSS文件未加载mod_rewrite

时间:2017-03-18 22:21:41

标签: php html css .htaccess mod-rewrite

我使用mod_rewrite时有一个奇怪的问题。

我的.htaccess文件中有此代码

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

它似乎有效,因为我能够重写

  

本地主机/ article.php?ID = 1

in

  

本地主机/信息/ 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>";

我也尝试在&#34; css / style.css&#34;之前添加斜杠,得到&#34; /css/style.css"但它似乎没有用。

有什么建议吗?谢谢你的建议。

1 个答案:

答案 0 :(得分:0)

使用绝对路径add / to 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>";
相关问题