Zend 和 modrewrite 无法正常协同工作

发布于 2024-09-15 23:19:37 字数 730 浏览 4 评论 0原文

我正在设置一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风铃鹿 2024-09-22 23:19:37

好吧,事情就是这样。

我的 DOCUMENT_ROOT 设置为 /var/www,而我的应用程序已用尽 /var/www/app1 中的所有内容。由于 RewriteBase / 行,它被重定向到 DOCUMENT_ROOT 而不是 APPLICATION_ROOT。我通过将该行更改为:

RewriteBase /app1

现在一切正常。

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:

RewriteBase /app1

and now everything works perfectly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文