Passing urlencoded url as parameter for controller / action on CakePHP

I am new to CakePHP, and because of this there are some basic things that I used with the Zend Framework that I beat Cake.

I am working on a project where I need to pass a named parameter to a controller / action. Setting the route and passing the parameter is quite simple, my problem is that the parameter is urlencoded url.

For example: http://www.cakephp.com/controller/action/http%3A%2F%2Fwww.google.com , regardless of the controller and setting the actions, it returns 404, but the transmission / controller / action / http: // www .google.com works in some way, the only problem is that it identifies http as a named parameter. In another way, if I execute /controller/action?url=http://www.google.com, it will work.

The work I used for this is to pass the value as a base64 encoded string, but this leads to some limitations. For example, if it is an API, you cannot guarantee that a system using the API can encode a base64 string.

In any case, the best solution would be to pass a url encoded string to the named parameter. The question is why CakePHP does not accept the urlencoded string as a parameter and why does it throw 404?

Thanks to everyone in advance.

+4
source share
1 answer

I added work around this problem. The previous answer, which pointed to the message, actually answered the question of why this is happening, and one of the solutions. It happens that the workaround for .htaccess on Apache is a little dangerous, as it will disable the security criteria.

There are two ways to work with this code (and I use both):

  • Send all urls as base64 encoded strings
  • Accept URLs as named parameters, but as you noticed, it converts any http: // to http: /, so you need to correctly determine when this happens, and only then correct the line.

This is far from an ideal solution, but it is definitely a practical option.

+5
source

Source: https://habr.com/ru/post/1336360/


All Articles