如果索引控制器未大写,Zend 自定义路由将无法工作?
我正在我的共享主机上测试 Zend 项目。我将所有内容保存在文件夹“Zend-project”中,而不是在服务器公共根目录中(因为我还有另一个项目!)。
这是结构:
/public_root
/zend-project
/application
/configs
application.ini
/controllers
/layouts
/views
bootstrap.php
/css
/images
/javascript
/zend-library
.htaccess
index.php
我必须对项目进行一些调整,因为我无法更改共享托管上的 document_root,因此我将 .htaccess 编辑为:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/favicon.ico$ [OR]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /zend-project/index.php [NC,L]
但最后,除了单个 URL 路由之外,一切似乎都工作正常我在引导程序中添加到路由器中。
编辑:我尝试创建一个新的控制器“TestController”..使用单个操作(称为“test”)我尝试用小写控制器输入网址(mysite.com/zend-project/test/test)并且它正在工作!因为我怀疑“index”这个词本身有问题!因为任何其他控制器都可以作为一个魅力
这是 bootstrap.php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initRoutes()
{
$frontController=Zend_Controller_Front::getInstance();
$router=$frontController->getRouter();
$router->removeDefaultRoutes();
$router->setGlobalParam('lang','en');
$router->addRoute(
'lang',
new Zend_Controller_Router_Route(':lang/:controller/:action',
array('lang'=>':lang',
'module'=>'default',
'controller'=>'index',
'action'=>'index'
)
)
);
//the following route is not working remotely.
//Is working on local environment
$router->addRoute(
'langController',
new Zend_Controller_Router_Route(':controller/:action',
array(
'module'=>'default',
'controller'=>'index',
'action'=>'index'
)
)
);
$router->addRoute(
'langIndex',
new Zend_Controller_Router_Route(':lang',
array('lang'=>':lang',
'module'=>'default',
'controller'=>'index',
'action'=>'index'
)
)
);
$router->addRoute(
'langNothing',
new Zend_Controller_Router_Route('',
array(
'module'=>'default',
'controller'=>'index',
'action'=>'index'
)
)
);
}
}
我尝试输入以下网址(基于我创建的自定义路由) )和一切似乎都有效:
//this points to the pair controller/action -> index/index
mysite.com/zend-project/
//this points to the pair controller/action ->index/index in english lang
mysite.com/zend-project/en
//this points to the pair controller/action ->index/rooms in english lang
mysite.com/zend-project/en/index/rooms
但每当我输入:
mysite.com/zend-project/index/index
我都会收到以下消息: 未找到。在此服务器上未找到请求的 URL /zend-project/index/index。
看起来请求没有到达index.php文件..可能是.htaccess问题?或者感谢
编辑
发现通过用大写字母输入损坏的路由的控制器它可以工作:
//this works.Controller has capital letter
mysite.com/zend-project/Index/index
//this do not work.Controller has not capital letter
mysite.com/zend-project/index/index
为什么?? (顺便说一句,我在Linux服务器上..)
I'm testing a Zend project on my shared-hosting.I keep everything inside a folder 'Zend-project' not on the server public-root (cause I have there another project!).
this is the structure:
/public_root
/zend-project
/application
/configs
application.ini
/controllers
/layouts
/views
bootstrap.php
/css
/images
/javascript
/zend-library
.htaccess
index.php
I had to tweak a little the project cause I just can't change my document_root on a shared-hosting so I edited the .htaccess to this:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/favicon.ico$ [OR]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /zend-project/index.php [NC,L]
but at the end everything seems to work fine except a single Url Route that I added to the router in my bootstrap.
edit:I tried creating a new controller 'TestController'..with a single action (called 'test')I tried to type the url with the controller lowercase (mysite.com/zend-project/test/test)and it's working!As I suspected there is something wrong with the 'index' word itself!cause any other controller works as a charme
this is bootstrap.php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initRoutes()
{
$frontController=Zend_Controller_Front::getInstance();
$router=$frontController->getRouter();
$router->removeDefaultRoutes();
$router->setGlobalParam('lang','en');
$router->addRoute(
'lang',
new Zend_Controller_Router_Route(':lang/:controller/:action',
array('lang'=>':lang',
'module'=>'default',
'controller'=>'index',
'action'=>'index'
)
)
);
//the following route is not working remotely.
//Is working on local environment
$router->addRoute(
'langController',
new Zend_Controller_Router_Route(':controller/:action',
array(
'module'=>'default',
'controller'=>'index',
'action'=>'index'
)
)
);
$router->addRoute(
'langIndex',
new Zend_Controller_Router_Route(':lang',
array('lang'=>':lang',
'module'=>'default',
'controller'=>'index',
'action'=>'index'
)
)
);
$router->addRoute(
'langNothing',
new Zend_Controller_Router_Route('',
array(
'module'=>'default',
'controller'=>'index',
'action'=>'index'
)
)
);
}
}
I tried to type the following urls (based on the custom routes I created)and everithing seems to work:
//this points to the pair controller/action -> index/index
mysite.com/zend-project/
//this points to the pair controller/action ->index/index in english lang
mysite.com/zend-project/en
//this points to the pair controller/action ->index/rooms in english lang
mysite.com/zend-project/en/index/rooms
But whenever I type:
mysite.com/zend-project/index/index
I receive the following message:
Not Found.The requested URL /zend-project/index/index was not found on this server.
It looks like the request doesn't reach the index.php file ..maybe an .htaccess problem??or what
thanks
edited
Found out that by typing the broken route's controller with capital letter it works :
//this works.Controller has capital letter
mysite.com/zend-project/Index/index
//this do not work.Controller has not capital letter
mysite.com/zend-project/index/index
why??
(by the way I'm on linux server..)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 httpd.conf 中删除此选项
Options Includes ExecCGI MultiViews FollowSymLinks Indexes
Remove this from httpd.conf
Options Includes ExecCGI MultiViews FollowSymLinks Indexes