I have an mulitisite instalation. I would like to make site/[site.name.com]/files not be able to be accessed by other domain. When I added

# make the subdirectory to invisible (cannot be access by web server)
RewriteCond %{HTTP_HOST} ^(www.)?other-example.com$ [NC]
RewriteCond %{REQUEST_URI} ^/sites/example.com/(.*)$ [OR]
RewriteRule ^(.*)$ - [L,R=404]

in .htacess, imagecache does not work. Does anybody know why? and how can I solve the problem.

Note: I also posted this issue related to http://drupal.org/node/224913#comment-2529448.

hosais

Comments

kvarnelis’s picture

Category: feature » bug

I have the same problem.

I have three sites I want imagecache on. They have identical sets of modules and versions of Drupal (everything is the most recent according to update status and yes beta10 of imagecache). They have identical htaccess files.
All 3 are running on the same server.

1 is sitting in a directory by itself. It works fine with anything I throw at it.

The other two are in a multisite install. These do not work. When I try to create a preset, it gives me a broken image for the druplicon sample.

I have verified that the sample image is in the proper directory.

On one site found an imagecache directory had been created. Since it seemed to have problems, I deleted it, recreated it and gave it 777 permissions.

Still no luck. Absolutely no difference in behavior.

When I open the link to the sample image, it brings me my site.

This seems like a common problem with imagecache. It's such a great module and I'd love to see it work on these two sites.

kvarnelis’s picture

I solved my problem, it was a matter of .htaccess in the files directory in the subdirectory for my site.

.htaccess was set to

SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
Options None
<IfModule mod_rewrite.c>
  RewriteEngine off
</IfModule>

There's the problem, rewriteengine off!

First I tried to set it to the .htaccess file in the troubleshooting imagecache page, which says it should be

SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
Options +FollowSymlinks

That killed the theme for my site completely.

I then turned to an .htaccess file auto-generated by Drupal 6 (the first one was probably from Drupal 5).

This time, the code read

SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
Options None
Options +FollowSymLinks

That worked!

Andrew Gorokhovets’s picture

In my case the problem is not solved. I have checked up all as is specified here http://drupal.org/node/224913. However on page admin/build/imagecache/1 the image does not appear. Instead of it only URL. Besides on page, where is used imagecache, images is not present. The reason that imagecache not truly generates URL. In my case on page I see URL to image

 src = "http://example.com/sites/example.com/files/imagecache/product/pricep/pricep-dlya-lodki/pl2t-76/4.jpg"

On page admin/settings/file-system my configuration is:
files: sites/example.com/files
temp: sites/example.com/temp

P.S When I use only imagefield it's work greate.

Andrew Gorokhovets’s picture

Status: Active » Fixed

I have committed an error. I have not included neither ImageAPI GD2, nor ImageAPI ImageMagick
Now all fix.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

roball’s picture

Title: Multisite -> .htaccess -> imagecache does not work » No imagecache image is generated when a .htaccess file containing a RewriteRule is present
Version: 6.x-2.0-beta10 » 6.x-2.0-rc1
Status: Closed (fixed) » Active

andrey_jw and kvarnelis had unrelated setup mistakes which they could fix, but the problem reported by hosais is still not solved, unfortunately, and I was also hit by it.

Steps to reproduce:

Put an .htaccess file into the "File system path" directory defined at admin/settings/file-system (usually, something like sites/example.com/files), with the following content:

SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
Options None
Options +FollowSymLinks

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^(www\.)?example\.com$ [NC]
    RewriteRule ^.* - [F]
</IfModule>

When an image is uploaded to a node using the ImageField module, and the display style of that image is set to a thumbnail format, no image will be created at /sites/example.com/files/imagecache/path_to/my_image.png, so the resulting image will have a broken src - thus no image is displayed.

When commenting out the line

    RewriteRule ^.* - [F]

to

#    RewriteRule ^.* - [F]

the problem is gone, so the ImageCache module has definitely a problem with Apache's RewriteRule directive.

roball’s picture

Title: No imagecache image is generated when a .htaccess file containing a RewriteRule is present » No imagecache image is generated when a .htaccess file containing a RewriteRule to protect the file directory is present
Assigned: Unassigned » roball
roball’s picture

Category: bug » support
Status: Active » Fixed

I have now found how to solve this issue:

In the .htaccess file residing in the sites/example.com/files directory, the mod_rewrite section should read as follows:

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteCond %{REQUEST_URI} ^/sites/example\.com/files/imagecache/
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ /index.php?q=sites/example.com/files/$1 [L,QSA]

  RewriteCond %{HTTP_HOST} !^(www\.)?example\.com$ [NC]
  RewriteRule ^.* - [L,F]
</IfModule>

Works fine for me with Apache 2.2 :-)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.