According to :
.htaccess rewrite image file to php script
I am trying to Rewrite an image to an action, in cakephp 2.5. The .htaccess used is the one inside /app/webroot/ according to this post: Adaptive images CakePHP htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteRule ^img/logo.png$ /users/display_details [NC,L]
</IfModule>
The result displayed is 'missing controller' page, with.
<?php
class ImgController extends AppController {
}
Any guess to make this working ? Thanks.
Your rule will not change any of the server variables that CakePHP looks up for matching its routes (
PATH_INFO,REQUEST_URI,SCRIPT_NAME,HTTP_X_REWRITE_URL), so CakePHP will still see and match on/img/logo.png, it will ignore theREDIRECT_URLthat is being set by your rule, hence it will look forImgController.You could try to set the
PATH_INFOvariable via theE(envelope) flag, like:This should set
$_SERVER['PATH_INFO']to/users/display_details, and CakePHP should be able to match a route against it.See also