开发者

Encoded slashes break route in Cakephp

开发者 https://www.devze.com 2023-04-01 00:52 出处:网络
I have the following route in my routes.php Router::connect(\'/:lang/detail/:id/*\', array(\'controller\' => \'main\', \'action\' => \'detail\'), array(\'lang\' => \'[开发者_开发问答a-z]{3}\

I have the following route in my routes.php

Router::connect('/:lang/detail/:id/*', array('controller' => 'main', 'action' => 'detail'), array('lang' => '[开发者_开发问答a-z]{3}'));

and the following URL works

http://www.cyclistsroadmap.com/eng/detail/1380/Ferguson++119th/

But the following does not:

http://www.cyclistsroadmap.com/eng/detail/1380/Ferguson+%2f+119th/ (%2f is url encoded slash)

It would seem to me that greedy star should take anything but it doesn't seem to like the encoded slash in there. Is this something that I am doing wrong or is this a genuine bug in Cakephp?


Make sure you have enabled the AllowEncodedSlashes directive in Apache:

AllowEncodedSlashes on

More info can be found here:

http://httpd.apache.org/docs/2.2/mod/core.html#allowencodedslashes


Although this may not apply to your situation, I had a similar problem that I fixed in the following way.

We keep a URL for a tree like set of pages with it's path that get's updated on save. Ex:

Name          | Path
Home          | /
- Support     | /support
-- Legal      | /support/legal
-- Privacy    | /support/privacy
- About       | /about
-- Who We Are | /about/who-we-are

We then pass the path as an argument to our controller. The regular Router::* methods will encode the slashes in these. What we do instead is the following:

$redirect = explode('/', $path);
$redirect['controller'] = 'my_controller';
$redirect['action']     = 'my_action';
$this->redirect($redirect);

This let's cake re-encode the slashes for me. Then you can re-assemble them in the controller

$path = implode('/', $this->request->params['pass']);
0

精彩评论

暂无评论...
验证码 换一张
取 消