.htaccess rewrite without it affecting relative image/css/js URLs?

左心房为你撑大大i 提交于 2019-12-07 22:18:47

问题


I need some simple help with my htaccess file, thank you in advance.

I have a number website URLs, such as:

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

I want to use the RewriteEngine to change the above links to the following respectively:

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

Below is the .htaccess code I am using:

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

This works, however all of my images, CSS files and JS files no longer load because the page is trying to fetch the wrong URLs. For example "/images/blah.jpg" is instead loading as "/solutions/images/blah.jpg".

How can I modify the htaccess code to prevent relative URLs from changing?

Thank you!


回答1:


Add this line <BASE href="http://www.yoursitename.com/"> to your page inside the <head> tag as follows:

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


来源:https://stackoverflow.com/questions/14269919/htaccess-rewrite-without-it-affecting-relative-image-css-js-urls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!