[英].htaccess rewrite image in cakephp 2.5
According to : 根据 :
.htaccess rewrite image file to php script .htaccess将图像文件重写为php脚本
I am trying to Rewrite an image to an action, in cakephp 2.5. 我试图在cakephp 2.5中将图像重写为动作。 The .htaccess used is the one inside /app/webroot/ according to this post: Adaptive images CakePHP htaccess
根据这篇文章,使用的.htaccess是/ app / webroot /中的一个: 自适应图像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 the REDIRECT_URL
that is being set by your rule, hence it will look for ImgController
. 您的规则不会更改CakePHP查找以匹配其路由的任何服务器变量(
PATH_INFO
, REQUEST_URI
, SCRIPT_NAME
, HTTP_X_REWRITE_URL
),因此CakePHP仍会在/img/logo.png
上看到并匹配,它将忽略REDIRECT_URL
由您的规则设置,因此它将查找ImgController
。
You could try to set the PATH_INFO
variable via the E
(envelope) flag, like: 您可以尝试通过
E
(信封)标志设置PATH_INFO
变量,例如:
RewriteRule ^img/logo.png$ index.php [NC,L,E=PATH_INFO:/users/display_details]
This should set $_SERVER['PATH_INFO']
to /users/display_details
, and CakePHP should be able to match a route against it. 这应该将
$_SERVER['PATH_INFO']
为/users/display_details
,并且CakePHP应该能够针对它匹配路由。
See also 也可以看看
I did not try your solution because I found a way to make it working. 我没有尝试过您的解决方案,因为我找到了使之起作用的方法。
Into the routes.php I added this line 我在routes.php中添加了这一行
Router::connect('/images/logo.png', array('controller' => 'users', 'action' => 'display_details'));
It's kind of weird, true but it works. 有点奇怪,是对的,但确实有效。 The real image is
/img/logo.png
so inside the display_details , I have a code to display the real image and run some code into this function too. 真实的图像是
/img/logo.png
所以在display_details里面,我有一个代码来显示真实的图像,并在此函数中运行一些代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.