zend-framework - Zend 框架 : strange url rewrite behavior

标签 zend-framework mod-rewrite routing

我的 Zend Framework 应用程序出现奇怪的行为。

我运行这个 url,希望让索引 Controller 运行 1234567890 操作。

http://hello.com/index/1234567890?test=http%3A%2F%2Fworld.com%2Findex.php

但是我得到这样的异常:

Message: Invalid controller specified (4567890) 

奇怪的是,页面上的所有 URL 现在都链接到:

http://hello.com/index.php/index/1234567890

代替:

http://hello.com/index/1234567890

请注意,被错误地注入(inject)到 URL 中的 index.php 字符串有 9 个字符,它与 index/1234567890 字符串的截断相同,以获取错误的 Controller 名称。

另一件事是注入(inject)的 index.php 与示例中 url 编码的 get 参数中的 index.php 相关联。

怎么了?这是 Zend 中的错误吗?还是我做错了什么?

这是我的 .htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]

最佳答案

你没有在你尝试调试它的方式上投入太多,所以我徘徊到我自己的本地主机并试了一下你的网址。瞧瞧我做同样的事情,我尝试了两种不同的 modrewrite 方法:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]

他们都在做同样的事情。在花了相当多的时间玩弄 url 并查看请求参数在我的错误页面上的样子之后,我所能想到的是 Zend Framework 中的默认路由模式存在重大故障,或者使用您的 modrewrite 正在向 url 中发送请求的文件名。

所以我将我的主要 index.php 文件更改为 main.php 并分别在我的 modrewrite 中,它工作正常,仔细检查了 main.php 在 url 中不会弄乱它,它没有。

因此,虽然没有 promise 任何东西,但如果您将 index.php(被写入并包含您的 Bootstrap )重命名为 main.php 或任何您喜欢的名称,并在您的 modrewrite 中反射(reflect)出来,您应该已经准备就绪!

祝你好运!

关于zend-framework - Zend 框架 : strange url rewrite behavior,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/627460/

相关文章:

.htaccess - 需要通过使用.htaccess提供禁止的错误403来阻止Google bot,Bing bot和具有空用户代理的客户端

url - Angular2获取url查询参数

php - Zend ACL 与模块和 Controller 访问问题

php - Zend_Form 获取错误

apache - 如何在 wamp 上配置 codeigniter mod_rewrite?

wordpress - .htaccess 和 wordpress 301 重定向不在批准的 IP 地址列表中的每个人?

networking - 网络系统帮助 : How to route an external request, 通过主机名到内部 ip?

ruby-on-rails - 没有id的Rails 3资源路由

php - magento 1.9 - 将 block 移动到产品页面

zend-framework - 您使用什么搜索表单?获取查询或路由参数?