我客户的网站当前运行在带有 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 时,我得到 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第 0 行
,但是如果我直接访问路由 http://domain.tld/index.php/noticias/frontend/list/它工作正常。
更新
我找到了一个可以改变某些框架行为的可行解决方案。如果有人在无需更改框架(可能在 apache 或 php 配置中)的情况下有解决方案,我会欣然奖励答案。
最佳答案
正如@user3584460 所说,我决定更改所有路由以将所需的 Controller /操作作为查询字符串参数传递。这是它是如何完成的。
我更改了所有路由以传递 _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
方法中添加了以下几行:
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;
}
现在它工作正常。
关于php - 未指定输入文件 - apache 和 php-fastcgi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32255289/