我客户的网站当前运行在带有 mod_php 的 apache 服务器上。所有应用程序的路由都在 .htaccess 文件中定义(请参阅下面的代码)。现在他正尝试迁移到运行 apache 和 php-fastcgi 的服务器,但路由不再有效。
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule "^noticias/?$" index.php/noticias/frontend/list/ [L,QSA]
RewriteRule ^.*$ index.php [NC,L]
</IfModule>
当我访问时http://domain.tld/noticias http://domain.tld/noticias, I get No input file specified
,并在 apache error_log 中[fcgid:warn] mod_fcgid: stderr: PHP Warning: Unknown: function '1' not found or invalid function name in Unknown on line 0
,但是如果我直接访问路线http://domain.tld/index.php/noticias/frontend/list/ http://domain.tld/index.php/noticias/frontend/list/效果很好。
UPDATE
我找到了一个可以改变框架行为的可行解决方案。如果有人有一个解决方案,而无需更改框架(可能在 apache 或 php 配置中),我将很高兴地向答案授予赏金。
正如 @user3584460 所建议的,我决定更改所有路由以将所需的控制器/操作作为查询字符串参数传递。这是如何完成的。
我更改了所有路由以传递 url 参数:
RewriteRule "^noticias/?$" index.php?_url=/noticias/frontend/list/ [L,QSA]
这样我就不会收到错误“未指定输入文件”,但框架(zend)将无法识别该路线,并且始终会显示主页。
路线调度员预计$requestUri
变量的格式为index.php/module/controller/action
,但随着变化.htaccess
, 它是index.php?_url=/module/controller/action
。所以我必须做出一些改变Zend_Controller_Request_Http
类,所以它会进行转换。
所以我将以下几行添加到setRequestUri
method:
public function setRequestUri($requestUri = null)
{
// ...
// begin changes
preg_match('/_url=([a-zA-Z0-9\/\-_\.]+)&?(.*)/', $requestUri, $matches);
if (count($matches) == 3)
$requestUri = '/index.php' . $matches[1] . '?' . $matches[2];
// end changes
$this->_requestUri = $requestUri;
return $this;
}
现在效果很好。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)