我的客户的网站目前正在使用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
,在apacheerror_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/它运行良好。
更新
我找到了一个有效的解决方案来改变一些框架行为。如果有人有一个不需要更改框架的解决方案(可能是在apache或php配置中(,我会慷慨地给予答案。
根据@user3584460的建议,我决定更改所有路由,以将所需的控制器/操作作为querystring参数传递。这是怎么做到的。
我更改了所有路由以传递一个_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;
}
现在它运行良好。
使用noticias
:更改线路
RewriteRule ^noticias/?$ index.php/noticias/frontend/list/ [L]
我们有时会在使用重写的网站上看到这种情况。我们通过更改重写来解决这个问题。旧的线路类似于:
RewriteRule ^(.*)$ _routing.php/$1 [L]
我们把它改成:
RewriteRule ^(.*)$ _routing.php [L]
这解决了问题。