Silex无法处理具有%2f的网址变量 [英] Url Variables with %2f not handled by silex

查看:69
本文介绍了Silex无法处理具有%2f的网址变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对silex非常陌生,但是有基于Java的MVC框架的经验。

I am very new to silex, but have experience with Java based MVC frameworks.

我遇到的问题似乎是如何在URL参数中接受某些特殊字符。

The problem I have seems to be how to accept certain special characters in URL arguments.

我有一个这样定义的控制器:

I have a controller defined as such:

$app->get('/editPage/{fileName}', function ($fileName) use ($app,$action) {
    return $app['twig']->render('edit.twig.html',$action->editPage($fileName));
});

这对以下网址非常有用:

and this works great for urls like:


  1. /myapp/editPage/file.html

  2. /myapp/editPage/file-2.html

,但是如果我通过编码 /或%2F,则路由没有被拾取,并且得到404。
1. / myapp / editPage / folder% 2Ffile.html

but if I pass an encodes "/" or %2F, the route is not picked up, and I get a 404. 1. /myapp/editPage/folder%2Ffile.html

mod_rewrites规则应将所有不存在的文件路径路由到定义了silex的index.php,因此我不确定发生了什么。

The mod_rewrites rules should route any non-existent file paths to the index.php where silex is defined, so I am not sure what is happening.

我只需要一种使用 /捕获此特定页面的值的方法。没有冲突的子页面,因此,如果有一种通配符路径 /editPage/{.*|filename}/或明显缺少的东西,我会丢失。

I just need a way to capture values with "/" for this particular page. There are no conflicting childpages, so if there is a way to wildcard the path "/editPage/{.*|filename}/" or something obvious I am missing.

推荐答案

对于Silex来说,这不是问题,但是对于Apache。

It's not an issue with Silex but with Apache.

出于安全目的,Apache拒绝将设计的斜杠作为URI的一部分而拒绝。查看此答案: https://stackoverflow.com/a/12993237/358813

Apache rejects by design encoded slashes as part of the URI for security purposes. See this answer: https://stackoverflow.com/a/12993237/358813

作为一种变通方法,在查询字符串中传递值是完全可以的:

As a workaround passing the value inside a query string is completely fine:

http://example.com/? file =%2Fpath%2Fto%2Ffile 将起作用,只要您相应地配置Silex。

http://example.com/?file=%2Fpath%2Fto%2Ffile will work, provided you configure Silex accordingly.

这篇关于Silex无法处理具有%2f的网址变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆