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']);
精彩评论