【问题标题】:URL-encoded parameter breaks default Zend rewrite rulesURL 编码的参数破坏了 Zend 的默认重写规则
【发布时间】:2012-02-25 14:28:05
【问题描述】:

我使用的是标准 Zend /public/.htaccess 文件(如下所示)。

目前我正尝试将用户转发到特定的控制器/动作,并提供成功重定向 URL 作为 URL 参数。

生成的 URL(通过 Zend 的 URL 视图助手组装和编码)如下所示:

localhost/crop/index/successRedirect/localhost%2Fprofile%2Fbasic

但是这种模式显然违反了 Zend 包 mod_rewrite 的默认规则:访问 URL 会产生标准的 Apache 404 错误; Zend 没有收到请求。

当最终参数手动重新形成如下时,请求按预期工作:

localhost/crop/index/?successRedirect=localhost%2Fprofile%2Fbasic

但是,这需要一个骇人听闻的两步 URL 生成过程。如果视图助手生成的 URL 独立工作,那将是理想的。

可以做些什么来允许 url 编码通过?任何见解将不胜感激!

这些是我的 .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]

像这样启用 RewriteLog 不会产生失败模式的输出:

RewriteLogLevel 9
RewriteLog "<path>/rewrite.log"

我尝试了以下两个问答中提出的解决方案,没有任何变化:

【问题讨论】:

标签: zend-framework .htaccess mod-rewrite url-rewriting urlencode


【解决方案1】:

AllowEncodedSlashes On 使用您的确切测试 URL 为我解决了这个问题。但是根据http://httpd.apache.org/docs/2.0/mod/core.html#allowencodedslashes,该指令需要在服务器配置或虚拟主机中。它在 .htaccess 文件中不起作用。

我个人会选择查询字符串解决方案。您能否详细说明这是一个两步 URL 生成过程的含义?我原以为语法与使用普通 URL 帮助程序非常相似。

【讨论】:

  • 果然。在/etc/apache2/apache2.conf 中设置这个指令——我最初的尝试——没有效果。我刚刚尝试在虚拟主机(/etc/apache2/sites-available/default)中设置它并且成功。谢谢!
猜你喜欢
  • 2012-03-02
  • 2012-02-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-23
  • 2022-01-17
  • 2011-03-03
  • 2014-08-14
相关资源
最近更新 更多