问题
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