Drupal imagecache problems in IIS 7
Posted by Daniel B. Roy on 16 February 2010
Tag(s): Webapplicaties
While migrating the site of one of our clients to a new server, I ran into a strange problem. The site is Drupal-based, and images coming from Drupal's imagecache were not always shown: all images with a filename containing spaces were broken, while other images were shown perfectly.
I managed to solve this, thanks to this helpful post, but since Drupal on IIS isn't really top of mind in the Drupal community, I'll just give you some important pointers when working with Drupal imagecache on IIS 7:
-
To get anything to work, you'll need HTTP rewriting and CleanURL's enabled. Starting with IIS 7, there is support for URL rewriting by the web server, see this link, but for historical reasons, we use ISAPI_rewrite. There are several posts on the Internet regarding configuration of CleanURL on IIS.
-
Imagecache writes its own .htaccess file in the 'files' directory. This file contains directives that don't do anything on IIS, but unfortunately, it can break your URL rewriting for anything in the 'files' directory. Deleting the .htaccess will temporarily work, but imagecache will eventually recreate the .htaccess.
The solution is to copy the .htaccess file from the root dir to the 'files' dir. Since imagecache now sees there is a .htaccess file present, it won't touch anything. You may need to slightly alter the rewrite rule in the .htaccess file that is in your 'files' directory, as described here. For me this wasn't necessary.
- For IIS7 there is an additional step, which is what gave me problems. Imagecache uses '+'-signs for filenames with spaces, so 'file 1.jpg' becomes 'file+1.jpg' when requested from the cache. However in IIS7, URL's containing a + in the main part of the URL are blocked. To disable this setting, use the following command to create/edit the web.config file for your website:
%windir%\system32\inetsrv\appcmd config "<website name in IIS manager>"
-section:system.webServer/security/requestFiltering -allowDoubleEscaping:true
Following the above steps restored all imagecache functionality to the site. Hope this helps!
Read more about this project:
Website Museon
In opdracht van intraQuest ontwikkelde Infi de website voor het Museon in Den Haag.

