Making css image absolute paths goto the root of a sub directory, not the root of the main domain

末鹿安然 提交于 2019-12-10 21:47:03

问题


I have multiple sites for clients set up on a single development domain. So the structure looks like this:

developmentdomain.com/client1/site

developmentdomain.com/client2/site developmentdomain.com/client/anothersite

Every things works fine (including furls) if i have a base ref in the html and add a RewriteBase rule my htaccess file.

But for some if within the css i have:

background: url("/assets/images/someImage.png");

Its trying to find the image at this location: developmentdomain.com/assets/images/someImage.png

When it needs to be looking at: developmentdomain.com/client1/site/assets/images/someImage.png

I'm guessing i need to do a rewrite rule in the htacess, but what?

Oh and this is what i have in the htacces file for my RewriteBase

RewriteEngine On
RewriteBase /client1/site

Any help much appreciated.

Thanks Ben


回答1:


No need for rewrite rules. You just need to use relative urls instead of root-relative. So use:

background: url("assets/images/someImage.png");

or background: url("/images/someImage.png"); if the css is located in the assets folder. (You could use ../ to go up one folder if needed)



来源:https://stackoverflow.com/questions/8357526/making-css-image-absolute-paths-goto-the-root-of-a-sub-directory-not-the-root-o

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