【发布时间】:2013-09-17 10:39:59
【问题描述】:
我正在尝试使用 mod_rewrite 将我的博客 URL 转换为对 SEO 更友好的格式。我所有的文章都存储在一个简单的 MySQL 数据库中。每篇博客文章的网址如下所示:
http://www.test.com/blog?id=20&category=online%20php%20tutorials&pagename=how%20to%20customize%20functions
我已经设法使用 mod_rewrite 使它们看起来像这样:
http://www.test.com/blog/online-php-tutorials/how-to-customize-functions/20
这是我在 .htaccess 文件中调整的代码:
RewriteRule ^blog/([a-z0-9\-]+)/([a-z0-9\-]+)/([a-z0-9\-]+)/?$ /blog?id=$3&category=$1&pagename=$2 [L]
所以会发生这样的情况:当我单击 URL http://www.test.com/blog/online-php-tutorials/how-to-customize-functions/20 时,我的所有 CSS 和图像都没有加载,因为它试图从一个实际不存在的目录中加载它们。如何加载文件而无需创建包含我的网站 CSS 文件和图像的多个目录?
【问题讨论】:
-
对你的 CSS 和 JS 使用绝对引用,它会相对于网站的根目录加载它们。
标签: php mysql apache .htaccess mod-rewrite