.htaccess重写而不影响相对图像/ css / js URL?

时间:2013-01-11 00:47:00

标签: .htaccess mod-rewrite rewrite relative-url

我的htaccess文件需要一些简单的帮助,谢谢你。

我有一些网站网址,例如:

  • www.site.com/index.php?page_path=solutions-overview.html
  • www.site.com/index.php?page_path=solutions-a.html

我想使用RewriteEngine将上述链接分别更改为:

  • www.site.com/solutions/overview
  • www.site.com/solutions/a

以下是我正在使用的.htaccess代码:

RewriteEngine On
RewriteRule ^solutions/overview index.php?page_path=solutions-overview.html
RewriteRule ^solutions/a index.php?page_path=solutions-a.html

这样可行,但是我的所有图像,CSS文件和JS文件都不再加载,因为页面正在尝试获取错误的URL。例如“/images/blah.jpg”正在加载为“/solutions/images/blah.jpg”。

如何修改htaccess代码以防止相对URL发生变化?

谢谢!

1 个答案:

答案 0 :(得分:4)

将此行<BASE href="http://www.yoursitename.com/">添加到<head>标记内的页面,如下所示:

<head>
    <title>Your site title</title>
    <BASE href="http://www.yoursitename.com/">
    ....
</head>