I'm using CakePHP 2.1.0 and I noticed that if you want to access a controller's action then it doesn't matter what casing you use for the action name; you will always hit that action in the controller. However, the action will expect the view file to be named with the same casing that you used to access the action. So if I were to go to http://example.com/users/aDd, I would hit the code in the "Users" controller's "add" action as expected, but it would look for aDd.ctp, which doesn't exist. Is there a way to make it so that action names can only be accessed if they're lowercase or else they're considered a bad URL?
UPDATE: I think it's safest to do this on the CakePHP level rather than on the web server level. This way, if, for whatever reason, you want to have http://example.com/FoO be valid regardless of the casing but you want http://example.com/bar and http://example.com/users/add to only be accessible if lowercase, you can do that.
Does anybody see a flaw in adding this to the "App" controller's "beforeFilter" method?:
if ($this->request->params['controller'] != strtolower($this->request->params['controller']) || $this->action != strtolower($this->action)) {
$redirect = Router::url(array(
'controller' => strtolower($this->request->params['controller']),
'action' => strtolower($this->action)
) + $this->request->params['pass']);
foreach ($this->request->params['named'] as $key => $value) {
$redirect .= "/$key:$value";
}
$this->redirect($redirect);
}