3

I'm trying to get Matt Wilcox adaptive images to work with CakePHP without success. http://adaptive-images.com/

CakePHP comes with three .htaccess files of it's own. In in /, one in /app/ and one in /app/webroot/

I need to get these four files to work together in such a way that image-requests are sent to the file adaptive-images.php that I've put in the root.

This is the htaccess from adaptive-images

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    # Adaptive-Images -----------------------------------------------------------------------------------

    # Add any directories you wish to omit from the Adaptive-Images process on a new line, as follows:
    # RewriteCond %{REQUEST_URI} !some-directory
    # RewriteCond %{REQUEST_URI} !another-directory

    RewriteCond %{REQUEST_URI} !assets

    # Send any GIF, JPG, or PNG request that IS NOT stored inside one of the above directories
    # to adaptive-images.php so we can select appropriately sized versions
    RewriteRule \.(?:jpe?g|gif|png)$ adaptive-images.php

    # END Adaptive-Images -------------------------------------------------------------------------------
</IfModule>

This is cakes htaccess from root /

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

This is cakes htaccess from /app/

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]
</IfModule>

This is cakes htaccess from /app/webroot

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

I assume the rules from adaptive images has to come first in one of the files and potentially add an [L] for last rule or something. But the only thing I've managed to accomplish so far is breaking the paths to images /img/myimage.gifso that Cake starts to look for an ImgController instead.

The Apache logs doesn't give me anything of value.

Any suggestions?

Edit: Currently looks like this

My modified / - htaccess now looks like below. Cake gives me an error about a missing ImgController and no images are created in the ai-cache-folder that adaptive images is supposed to put them in.

<IfModule mod_rewrite.c>
   Options +FollowSymlinks
   RewriteEngine on

    RewriteCond %{REQUEST_URI} !assets
    RewriteRule \.(?:jpe?g|gif|png)$ adaptive-images.php

   RewriteCond %{REQUEST_URI} !adaptive-images\.php [NC]
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>
Kristoffer Darj
  • 183
  • 1
  • 10
  • Clarified the question a bit. CakePHP ships with three standard htaccess-files. Those are the only ones I use and now I want to add some additional rules to one or several of them to get things to work properly. – Kristoffer Darj Feb 27 '13 at 07:42
  • Updated a little more. Have tried [L] on the adaptive-image rule as well. – Kristoffer Darj Feb 27 '13 at 08:44
  • 1
    If you're using `app/webroot` as webroot in you apache virtualHost, then the other two .htaccess files can be probably left out in your question. I would also have suggested the [L], but apparently that's not the problem? – thaJeztah Mar 02 '13 at 16:35
  • 1
    Hm my guess (not behind a computer at the moment), is that you should keep the `RewriteCond %{REQUEST_FILENAME} !-d` and `RewriteCond %{REQUEST_FILENAME} !-f` in your CakePhp rewriterule block, otherwise 'physical' files will also be handled by index.php – thaJeztah Mar 02 '13 at 16:41

1 Answers1

0

Alright I got it working even if it's perhaps not the most optimal solution there is.

I only changed the htaccess in the /app/webroot-folder like below

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    RewriteCond %{REQUEST_URI} !debug_kit
    RewriteRule \.(?:jpe?g|gif|png)$ adaptive-images.php [L]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

and added the adaptive-images.php file to app/webroot It would perhaps be nicer to have the adaptive-images.php file in the Vendor directory but at least it works.

I made two changes in adaptive-images.php

$cache_path    = "app/tmp/cache/ai-cache";
$source_file    = $document_root.'/app/webroot'.$requested_uri;
Kristoffer Darj
  • 183
  • 1
  • 10