How to pass "/" via GET to URI?

SOLVE:

This URI works:

/controller/action?ret=%2F 

I want to pass an extra parameter "/" to the controller action. So I did this:

 $par1 = urlencode('/'); $this->_redirect('/controller/action/par1/' . $par1); 

But I get this error message:

 Not Found The requested URL /controller/action/ret// was not found on this server. 

When I call the controller action without any parameters or with the parameter "aaa", it works. These URIs work:

 /controller/action /controller/action/par1/aaa /controller/action/par1/jfhsdajkhfui454fs /controller/action/par1 /controller/action/par1/ 

You can put http://example.com in front of all the relative URIs above, and this is the same.

+7
php zend-framework
source share
3 answers

You do almost everything right. The only small mistake is that urlencode prefers to use the plus sign to indicate a space, which is suitable only for query parameters, and not for part of the path. rawurlencode will be better here.

However, this is not the reason why this does not work. You are already generating the path /controller/action/par1/%2F , which is correct.

This does not work in practice for you, because Apache is trying to protect you (rather inefficiently) from directory traversal issues. If you include the %2F sequence in the URL path, Apache will by default go over and show your own 404 page (ignoring any errordocument options). To disable this feature (IMO: misfeature), you can use the AllowEncodedSlashes directive.

If you really can get a coded slash when it gets back to your script, this is another worm worm. Due to the poor design of the PATH_INFO variable in the original CGI specification, many environments will not be able to see %2F as something other than unencrypted / , potentially disrupting the routing you make from the part path.

It is usually best to avoid slashes in parts of the path because Apache is not the only server or language to be confused by them. In general, you should use the query parameters to enter where you need to accept any string of bytes or characters, since parts of the path have practical problems on many servers with (a) / , (b) \ , (c) the NUL character and (d) empty lines.

+9
source share

Try %2F . I don't think urlencode is going to encode '/' because it is valid URL syntax.

[ Edit ]: Rate the votes, but it seems my answer is incorrect. See bobince correctly (and in much more detail) answer below above.

+2
source share
+1
source share

All Articles