.htaccess 不加载 CSS 和 JS


.htaccess does not load css and js

我有 2 个博客文件,一个是blogdetail.phpbloglist.php。我想做的是,如果有人进入这样的链接

http://mysite.com/blog

打开bloglist.php以及当有人进入时

http://mysite.com/blog/7

以打开blogdetail.php?id=7 .到目前为止,我的.htaccess看起来像这样

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^blog/([0-9]+)$ blogdetail.php?id=$1 [NC,L]
RewriteRule ^([a-zA-Z]+)$ $1.php [NC,L]
ErrorDocument 404 /404.php

但问题是当我在blog/7上输入时,页面打开但 CSS 没有加载。有没有办法在不使用 css 和 js 的绝对路径的情况下完成这项工作?谢谢你,丹尼尔!

您在 .htaccess 中缺少此规则

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/([0-9]+)$ blogdetail.php?id=$1 [NC,L]
RewriteRule ^([a-zA-Z]+)$ $1.php [NC,L]
ErrorDocument 404 /404.php

在开始时将 css 文件与 / 链接,一切都会好起来的。