我有一个htaccess文件,它映射http://www.myserver.com/home/ to http://www.myserver.com/index.php?section=homeThis part works fine. The issue I am facing now is, all my images and css reside in a sub-folder named assets, i.e. http://www.myserver.com/assets/images/ http://www.myserver.com/assets/css/ etc.After redirection the browser will look for the files under http://www.myserver.com/home/assets/images/which causes things to break, as this is not a valid path.I have been able to add another rewrite that maps the above to the correct sub-folder, however, Firebug shows that the images are residing in: http://www.myserver.com/home/assets/images/I know it's not really a problem, after all, my images and css are loading just fine with this rule.I'm just curious as to how I could make the path shown to be the actual path, which is: http://www.myserver.com/assets/images/Pasting my htaccess file below. Thank you very much beforehand.Options +FollowSymlinksRewriteEngine onRewriteRule ^([^/]+)/assets/(css|images|js)/(.*)$ /assets/$2/$3 [NC,L]RewriteRule ^([^/]+)/$ /index.php?section=$1 [NC,L] 最佳答案 问题是您没有考虑相对URL是在基本URI上解析的,该基本URI是使用该引用的HTML文档的URI。因此,相对URI路径(如assets/images/在HTML文档中的URI路径解析为/home/而不是/home/assets/images/。您无法使用mod_rewrite进行更改,因为URI解析是由客户端而不是由服务器完成的。唯一的解决方案是:使用/assets/images/ element更改基本URI(请注意,这会影响所有相对URI);使用绝对URI路径,例如BASE而不是相对的/assets/images/;调整相对URI路径,因此将assets/images/中的引用调整为/home/以反映路径深度。关于.htaccess - htaccess重写中断了相对路径,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18284652/
10-16 16:16