CakePHP routes named parameters in a base path (/)
I am getting user link with parameter r
. ( r:code
).
It works well on all pages :controller/:action/*
, but when I try to pass it to the base path (/) my webserver returns a 403 error.
Here is my file routes.php
:
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
Router::connectNamed(array('r' => '[\d]{4}'));
These urls work well:
http://example.com/pages/home/r:1234
http://example.com/apples/eat/r:1234
but it doesn't work:
http://example.com/r:1234
What's wrong?
Question . Is this a way to grab the referrer code from the URL? or is it better to use passed arguments? ( http://example.com/1234/controller/action/.......
)
source to share
Apache 2.2 actually has the APR feature test_safe_name()
intentionally disallowing this kind of ":" in URIs on Windows servers. because this is mainly for avoiding urls like http://www.mysite.com/C:/SomeFile.exe but is actually annoying. Also, the Windows function FindFirstFile()
will return ERROR_INVALID_NAME
instead ERROR_FILE_NOT_FOUND
for any name trying to access the data stream using a character.
Selecting the ":" character as a namespace separator in MediaWiki was unfortunate for use on Windows servers.
source to share
Use the get argument
If you use the get argument, your code will be much more reliable:
/?r=urlencodedurl
It is independent of routes and therefore won't break or otherwise be a problem, regardless of the URL used. You access args through the request object:
$r = $this->request->query['r']
source to share