Zend 和 modrewrite 无法正常协同工作
我正在设置一个 Zend 应用程序,并完成了在我的开发站上设置 modrewrite 和编写 .htaccess 文件(如下所示)的基本步骤。现在,当我转到项目的根目录时,Zend 可以正常工作,调用控制器并显示适当的页面。
但是,当我调用任何控制器时,我希望它重定向到相同的 index.php 文件,该文件又将其定向到适当的控制器和操作(例如 myurl/controller/action 将由 myurl/index.php 读取)然后会适当地重定向到操作)。
我怀疑这个问题与我设置 .htaccess 文件的方式有关,因为调用基本 url 确实可以正常工作。但我一直无法弄清楚出了什么问题。有人有建议吗?
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*)/(.*)$ index.php [NC,L]
RewriteRule ^(.*)/(.*)/(.*)$ index.php [NC,L]
RewriteRule ^(.*)/(.*)/(.*)/(.*)$ index.php [NC,L]
RewriteRule ^.*$ index.php [NC,L]
I'm setting up a Zend application, and went through the basic steps of setting up modrewrite on my development station, and writing an .htaccess file (shown below). Now, when I go to the root of my project, Zend works properly, calling the controller and displaying the appropriate page.
However, when I call any controller, I would expect it to redirect to the same index.php file, which would in turn direct it to the appropriate controller and action (e.g. myurl/controller/action would be read by myurl/index.php which would then redirect to the action appropriately).
I suspect that the issue is somehow related to how I've set up my .htaccess file, since calling the base url does work properly. But I haven't been able to figure out what's wrong. Does anyone have a suggestion?
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*)/(.*)$ index.php [NC,L]
RewriteRule ^(.*)/(.*)/(.*)$ index.php [NC,L]
RewriteRule ^(.*)/(.*)/(.*)/(.*)$ index.php [NC,L]
RewriteRule ^.*$ index.php [NC,L]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,事情就是这样。
我的 DOCUMENT_ROOT 设置为 /var/www,而我的应用程序已用尽 /var/www/app1 中的所有内容。由于
RewriteBase /
行,它被重定向到 DOCUMENT_ROOT 而不是 APPLICATION_ROOT。我通过将该行更改为:现在一切正常。
Okay, here's what it was.
My DOCUMENT_ROOT is set to /var/www while my application is running out of /var/www/app1 with everything set up in there. Because of the line
RewriteBase /
it was redirecting to the DOCUMENT_ROOT instead of to the APPLICATION_ROOT. I fixed it by changing that line to:and now everything works perfectly.