.htaccess重写而不会影响相对的图像/css/js URL? [英] .htaccess rewrite without it affecting relative image/css/js URLs?
问题描述
我的htaccess文件需要一些简单的帮助,在此先感谢您.
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
我想使用RewriteEngine将上述链接分别更改为以下内容:
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
下面是我正在使用的.htaccess代码:
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
这有效,但是由于页面试图获取错误的URL,所以不再加载我的所有图像,CSS文件和JS文件.例如,将"/images/blah.jpg"加载为"/solutions/images/blah.jpg".
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".
如何修改htaccess代码以防止相对URL更改?
How can I modify the htaccess code to prevent relative URLs from changing?
谢谢!
推荐答案
将此行<BASE href="http://www.yoursitename.com/">
添加到页面中的<head>
标记内,如下所示:
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>
这篇关于.htaccess重写而不会影响相对的图像/css/js URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!