With clean URLs turned on, when you have a background image in a theme, it seems to read the path of the image incorrectly, even if the path in the CSS file is, for example http://www......./images/image.jpg

For example:

I have, in my CSS file:

	background-image:  url("http://www.hostenz.co.nz/cms/themes/hostenz/images/tn_bg1.gif");

This works fine usually to 1 directory level, for example http://www.hostenz.co.nz/cms/admin, however if I go to http://www.hostenz.co.nz/cms/admin/access or http://www.hostenz.co.nz/cms/node/1, the images break, and the path is reported as http://www.hostenz.co.nz/cms/admin/themes/hostenz/images/tn_bg1.gif or http://www.hostenz.co.nz/cms/node/themes/hostenz/images/tn_bg1.gif.

I have tried using a variety of different paths. I figure it might be an .htaccess problem, as turning clean URLs off solves this issue. I did not have this problem on 4.6. (I still have 4.6 available at http://www.hostenz.co.nz/d46).

**update I have also tried commenting the first lines in .htaccess and replacing them with the working version from 4.6, but no go.

Where is the $base_url variable set, and would this have any effect?

Comments

markus_petrux’s picture

Try url(path/to/image) without quotes.

Also, you might want to set paths relative from the CSS file. If the CSS file and images are distributed like this:

/sites/mysite.com/themes/mytheme/styles.css
/sites/mysite.com/themes/mytheme/images/background.gif

Then you could do something like:

background-image: url(images/background.gif);
mgcarley’s picture

That's how it started off. My structure is:

/themes/hostenz/ (phptemplate files: style.css, page.tpl.php, node.tpl.php etc)
/themes/hostenz/images (misc images for the template, all referenced from style.css)
/themes/hostenz/css (custom css thing based on month)
/themes/hostenz/img (images relative to custom css thing)

There is only one site running on this codebase. I'll make the images relative again, but IIRC it breaks the images on the front page as well...

mgcarley’s picture

I should note, a direct request for this file http://www.hostenz.co.nz/cms/node/themes/hostenz/images/side_p1.gif (or any image file) simply brings up the front page, which is why I thought it might be an .htaccess problem.

My .htaccess file is the default one included with Drupal 4.7-RC3, though I did try copying the first few lines from my Drupal 4.6 install - no go. As I mentioned, turning off clean-urls does fix the problem in it's entirety (but then I don't have clean urls!)

mgcarley’s picture

D'oh. Overlooked the /node/ in the URL above. Maybe it's not .htaccess then...

markus_petrux’s picture

Category: bug » support

It seems :-)

This one works:
http://www.hostenz.co.nz/cms/themes/hostenz/images/side_p1.gif

My structure is:

/themes/hostenz/ (phptemplate files: style.css, page.tpl.php, node.tpl.php etc)
/themes/hostenz/images (misc images for the template, all referenced from style.css)
/themes/hostenz/css (custom css thing based on month)
/themes/hostenz/img (images relative to custom css thing)

if your CSS file is located at /themes/hostenz/css and your CSS related images are located at /themes/hostenz/img, then I think you would have to do something like this:

background-image: url(../img/background.gif);
beginner’s picture

Version: 4.7.0-rc3 » 4.7.2
Status: Active » Fixed

Is the site still running Drupal? It seems badly broken at the moment. all I can get on each request is a 404 or 500 php script that is broken itself. Whatever the issue was, the issue today is much more serious, and apparently not Drupal related.

The issue is 2 months old, without any feedback from the reporter...

Anonymous’s picture

Status: Fixed » Closed (fixed)